使用pre\\u get\\u posts可能有效。您能否尝试以下类似的方法,并告诉我是否满足您的需要:
function search_filter($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set(\'post_type\', array( \'post\', \'movie\' ) );
//Should do some sanitation on $GET too
if(isset($_GET[\'author\'])){ //Change to your field dropdown name
$query->set(\'meta_key\', \'author\'); //change to custom field name
$query->set(\'meta_value\', $_GET[\'author\']);
}
else if(isset($_GET[\'pubyear\'])){
$query->set(\'meta_key\', \'pubyear\');
$query->set(\'meta_value\', $_GET[\'pubyear\']);
}
}
}
}
add_action(\'pre_get_posts\',\'search_filter\');
更新:也可以更好地使用
$query->set(\'meta_query\'), array(..)...
根据您的需要