如何限制搜索查询并在WordPress中添加过滤器?

我在新博客文章网站上使用了dynamix wordpress主题, 当我尝试过滤文章时, 在结果页面中将显示所有文章。我也使用了许多插件来过滤帖子。例如搜索和过滤器以及MDTF。仍然在搜索结果页面中, 它显示所有可用的帖子


#1


将下面的代码放入function.php文件中, 并替换你的posttype

function searchfilter($query) {

    if ($query->is_search) {
        $query->set('post_type', array( 'your-custom-post-type-name' ) );
    }

    return $query;
}
add_filter('pre_get_posts', 'searchfilter');

来源:

https://www.srcmini02.com/63385.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_41859.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?