php查询,一次只能工作一个
我在我的wp网站上使用了这个php过滤器搜索框。 我知道这是错误的,因为过滤器只向我显示最后一个查询,我如何以两个查询工作的方式编写代码php查询,一次只能工作一个,php,jquery,wordpress,filter,Php,Jquery,Wordpress,Filter,我在我的wp网站上使用了这个php过滤器搜索框。 我知道这是错误的,因为过滤器只向我显示最后一个查询,我如何以两个查询工作的方式编写代码 function SearchFilter($query) { if ($query->is_search) { $query->set('post_type', 'post'); $query->set('post_type', 'course'); } return
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
$query->set('post_type', 'course');
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');
谢谢。您每次都在最后一个帖子类型上设置$query,这当然是错误的
换成
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', array( 'post', 'course' ) );
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');
非常感谢你!我是php的初学者,没有想过使用数组!现在我已经学会了,谢谢!