![](/img/trans.png)
[英]Wordpress- how to use 'category__not_in' in wp_query
[英]WP_Query - `category__not_in` not working when showing sticky posts
我正在尝试显示前4个没有videos
类别的即时贴,这是我当前的循环:
<?php $videos_cat_id = get_cat_ID('videos');
$args = array(
'post__in' => get_option('sticky_posts'),
'category__not_in' => $videos_cat_id,
'ignore_sticky_posts' => 1,
'posts_per_page' => 4,
);
$featured_loop = new WP_Query($args);
if ($featured_loop->have_posts()) :
while ($featured_loop->have_posts()) : $featured_loop->the_post(); ?>
<div class="col-sm-6 m-bottom p-left-none p-right-none">
<?php get_template_part('card-featured') ?>
</div>
<?php endwhile; wp_reset_postdata();
endif; ?>
但是我仍然看到带有videos
类别的帖子。 我不太确定为什么这个循环不尊重category__not_in
,有什么想法吗?
尝试这个:
您可能需要在category__not_in
提供一个数组值。 并且由于get_cat_ID()
函数返回字符串/整数,因此您可能需'category__not_in' => array($videos_cat_id)
-> 'category__not_in' => array($videos_cat_id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.