从 WP_Query 中排除类别
Excluding category from WP_Query
我正在尝试在自定义 "Class" 分类法的存档页面上显示特色 post,并希望在带有 slug [=15= 的类别中排除 post ] 和 "extra"。以下不排除这些类别:
$class = get_queried_object(); // Get the current class
$current_class = $class->term_id; //Get the current class ID
$extras_cat = get_cat_ID( 'extra' );
$class_work_cat = get_cat_ID( 'work' );
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'filmbites_class',
'field' => 'term_id',
'terms' => $current_class,
),
),
'category__not_in' => array( $extras_cat, $class_work_cat ),
'posts_per_page' => 1
);
$posts= new WP_Query($args);
if($posts->have_posts()) :
while($posts->have_posts()) :
$posts->the_post();
$featured_post = get_the_ID(); //get the ID of the post to be featured
endwhile;
endif;
我用错了 get_cat_ID()
函数。使用 slug 而不是类别名称。
我正在尝试在自定义 "Class" 分类法的存档页面上显示特色 post,并希望在带有 slug [=15= 的类别中排除 post ] 和 "extra"。以下不排除这些类别:
$class = get_queried_object(); // Get the current class
$current_class = $class->term_id; //Get the current class ID
$extras_cat = get_cat_ID( 'extra' );
$class_work_cat = get_cat_ID( 'work' );
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'filmbites_class',
'field' => 'term_id',
'terms' => $current_class,
),
),
'category__not_in' => array( $extras_cat, $class_work_cat ),
'posts_per_page' => 1
);
$posts= new WP_Query($args);
if($posts->have_posts()) :
while($posts->have_posts()) :
$posts->the_post();
$featured_post = get_the_ID(); //get the ID of the post to be featured
endwhile;
endif;
我用错了 get_cat_ID()
函数。使用 slug 而不是类别名称。