在您的wp_query
, 您应该使用NOT IN
我看不到。在你的论点中WP_Query()
, 您应该使用category__not_in
而不是cat
. 因此,请将代码更改为:
Excluding Single Category
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 15,
\'paged\' => $paged,
\'category__not_in\' => \'X\', // string
);
如果要排除多个类别,请在数组中指定类别ID的逗号,而不是字符串。检查以下代码
Excluding Multiple Categories and Displaying Posts That are from X and Y
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 15,
\'paged\' => $paged,
\'category__in\' => array(X,Y), // Array
\'post__not_in\' => array(X),
);
以下是完整查询:
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 15,
\'paged\' => $paged,
\'category__in\' => array(X,Y), // Array
\'post__not_in\' => array(X),
);
$your_query = new WP_Query( $args );
while( $your_query->have_posts() ):
$your_query->the_post();
the_title();
endwhile;
wp_reset_postdata();
Note: Use ID not the category slug or name