您正在为中的主查询设置参数pre_get_posts
操作,然后通过调用query_posts
(which you should never use).
如果要排除类别,请在相同的pre_get_posts
措施:
add_action( \'pre_get_posts\', \'add_my_post_types_to_query\' );
function add_my_post_types_to_query( $query ) {
if ( is_home() && $query->is_main_query() ){
$query->set( \'post_type\', array( \'post\', \'miss_behave\', \'emily_davies\',\'gemma_patel\',\'poppy_smythe\' ) );
$query->set( \'category__not_in\', array(4, 142, 143, 144) );
}
}
编辑-在其他查询中使用参数:
$the_query = new WP_Query(
array(
\'post_type\' => array( \'post\', \'miss_behave\', \'emily_davies\',\'gemma_patel\',\'poppy_smythe\' ),
\'category__not_in\' => array(4, 142, 143, 144)
)
);