所有分类
  • 所有分类

  • Warning: Attempt to read property "name" on null in /www/wwwroot/loudigu.com/wp-content/themes/modown/header.php on line 289

wordpress搜索为空时仍然返回结果问题

今天帮客户做搜索页面时,发现搜索结果为空时仍然返回结果。

可以在主题函数function.php加入下面代码:

//~搜索关键词为空
add_filter('request','uctheme_redirect_blank_search');
functionuctheme_redirect_blank_search($query_variables){
if(isset($_GET['s'])&&!is_admin()){
if(empty($_GET['s'])||ctype_space($_GET['s'])){
wp_redirect(home_url());
exit;
}
}
return$query_variables;
}

搜索为空时返回首页,或者指定其他页面,就可以解决搜索结果为空还返回结果

原文链接:https://loudigu.com/wordpress%e6%90%9c%e7%b4%a2%e4%b8%ba%e7%a9%ba%e6%97%b6%e4%bb%8d%e7%84%b6%e8%bf%94%e5%9b%9e%e7%bb%93%e6%9e%9c%e9%97%ae%e9%a2%98.html,转载请注明出处~~~
0
广告位招租
本站愿景:打造一个更专业的更完善的WP华语交流互助平台,助力WP华语生态蓬勃发展
显示验证码
没有账号?注册  忘记密码?