[英]Control Search Parameters in PHP Wordpress
PHP Wordpress中的搜索参数为空
当用户按下搜索按钮时,即使搜索字段为空,它也会查询字符串参数
www.example.com/?ssc=&sst=&s=
我如何检查它并从URL中删除(不允许)空参数
如果您知道表单所在的位置,请添加必填项以输入文本
<input type="text" name="s" id="search" value="<?php the_search_query(); ?>" required />
否则在主题目录中创建searchform.php
并添加以下代码
<form action="/" method="get">
<label for="search">Search in <?php echo home_url( '/' ); ?></label>
<input type="text" name="s" id="search" value="<?php the_search_query(); ?>" required />
<input type="image" alt="Search" src="<?php bloginfo( 'template_url' ); ?>/images/search.png" />
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.