我正在修改自定义存档页的查询。我正在使用pre\\u get\\u posts操作。我需要捕获一些GET变量来修改我的查询。对于一种自定义的帖子类型,它在归档页面上工作得很好,但对于其他类型的帖子,它却不起作用。它正在破坏我的导航菜单。
add_action( \'pre_get_posts\', \'search_provider\');
function search_provider($query){
if(is_post_type_archive(array(\'provider\'))){
$query->set( \'posts_per_page\', -1 );
$query->set( \'orderby\', \'title\' );
$query->set( \'order\', \'ASC\' );
if(isset($_GET[\'providersearch\']) && $_GET[\'providersearch\'] == \'Y\'){
if(!empty($_GET[\'s\']))
$query->set( \'s\', $_GET[\'s\'] );
} else {
$query->set (\'exclude\', array(10054, 10068));
}
}
}
返回内容后是否需要清除查询变量?