我试图将查询扩展软件与Wordpress集成,但wordpress搜索引擎是AND搜索器(返回包含查询中所有单词的内容,因此更广泛的是查询更少的结果返回)。 因为这个原因,当我使用具有扩展功能的查询时,搜索器返回的结果更少。 我想修改搜索的行为,并将其变成更像是搜索者的东西。在Wordpress搜索中修改查询
例子: 对于查询“物联网,物联网”,我想那些内容“物联网”的帖子,或“物联网,或两者
我已经通过这个阅读。文件(https://codex.wordpress.org/Class_Reference/WP_Query),我试图用这样的事情:
add_action('template_redirect', 'hooks_setup' , 20);
function hooks_setup() {
if (! is_home()) //<= you can also use any conditional tag here
return;
add_action('__before_loop' , 'set_my_query');
add_action('__after_loop' , 'set_my_query', 100);
}
function set_my_query() {
global $wp_query, $wp_the_query;
switch (current_filter()) {
case '__before_loop':
//replace the current query by a custom query
//Note : the initial query is stored in another global named $wp_the_query
$wp_query = new WP_Query(array(
'post_type' => 'post',
'post_status' => 'publish',
//others parameters...
));
break;
default:
//back to the initial WP query stored in $wp_the_query
$wp_query = $wp_the_query;
break;
}
}
但我不知道我需要在wp_query设置哪些参数我怎样才能做到这一点
你还没有问过问题,只是说明你想要做什么。请参阅[如何提出一个好问题](http://stackoverflow.com/help/how-to-ask)。 –