当用户在WordPress的搜索字段中使用Dot搜索时如何显示零结果

在wordpress网站中, 如果你使用点(。)字符进行搜索。 WordPress将显示结果中的所有帖子和页面, 但是当用户在wordpress搜索查询中使用dot(。)字符进行搜索时, 我想显示零结果。

请建议我如何在没有插件帮助的情况下完成这项工作


#1


尝试这个

function post_filter_func($query) {

    if (! is_admin()  && $query->is_main_query()  && $query->is_search()) {

        $search_query = $query->query_vars['s'];

        if($search_query =='.'){
             $query->set('post_type', array('none-post'));
             $query->set('s', '');
             unset( $query->query['s'] );
             $query->is_search = FALSE;
        }
    }
      return $query;
};

add_action( 'pre_get_posts', 'post_filter_func' );

来源:

https://www.srcmini02.com/65466.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_40928.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?