为了排除类别(或任何其他分类法)术语,您可以连接到pre_get_posts
:
add_action(\'pre_get_posts\', \'wpse41820_exclude_cat_from_front_page\');
function wpse41820_exclude_cat_from_front_page( $query ){
if( $query->is_main_query() && is_front_page() ){
$tax_query = array(array(
\'taxonomy\' => \'category\',
\'field\' => \'id\',
\'terms\' => array( 57 ),
\'operator\' => \'NOT IN\'
));
$query->set(\'tax_query\',$tax_query);
}
return $query;
}
要排除段塞,请更改
$tax_query
因此:
$tax_query = array(array(
\'taxonomy\' => \'category\',
\'field\' => \'slug\',
\'terms\' => array( \'term-slug\' ),
\'operator\' => \'NOT IN\'
));