个性化阅读
专注于IT技术分析

WP_Query-显示粘性帖子时,” category__not_in”不起作用

点击下载

我正在尝试显示前4个没有视频类别的即时贴, 这是我当前的循环:

<?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; ?>

但是我仍然看到带有视频类别的帖子。我不完全确定为什么此循环不遵守category__not_in, 有什么想法吗?


#1


尝试这个:


你可能需要在category_not_in中提供一个数组值。而且由于get_cat_ID()函数返回字符串/整数, 因此你可能需要这样做->’category__not_in’=> array($ videos_cat_id)

赞(0)
未经允许不得转载:srcmini » WP_Query-显示粘性帖子时,” category__not_in”不起作用

评论 抢沙发

评论前必须登录!