![](/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.