我正在取消设置查询变量author_name
用于在作者模板页面中查询帖子。我正在使用pre_get_posts
筛选主查询。
运行查询后,我需要将author_name
查询变量。
这就是我取消设置的地方。
function wpquery( $query )
if ( $query->is_author() && $query->is_main_query()) {
$query->set( \'post_status\', $post_status );
unset( $query->query_vars[\'author_name\'] );
$tax_query = array(
array(
\'taxonomy\' => \'tax\',
\'field\' => \'name\',
\'terms\' => $var
)
);
$query->set( \'tax_query\', $tax_query );
}
add_action( \'pre_get_posts\', \'wpquery\' );
查询运行后,我必须设置author_name