您需要为pre_get_posts
过滤器,您可以在其中设置所需内容。请注意,您应该只更改搜索查询,因此您必须检查is_search()
方法返回true。挂钩应如下所示:
add_filter( \'pre_get_posts\', \'wpse8170_pre_get_posts\' );
function wpse8170_pre_get_posts( WP_Query $query ) {
if ( $query->is_search() ) {
$query->set( \'post_type\', array( \'resources\' ) );
$query->set( \'meta_query\', array(
array(
\'key\' => \'resource_usertype\',
\'value\' => array(\'Public\', \'Students\', \'Alumni\'),
\'compare\' => \'IN\',
)
) );
}
return $query;
}