繁体   English   中英

Wordpress - 类别未显示所有帖子

[英]Wordpress - Category not showing all posts

        <?php
            $wpb_all_query = new WP_Query(array('post_type'=>'post', 'post_status'=>'publish', 'posts_per_page'=>-1));

            if ( $wpb_all_query->have_posts() ) : ?>

            <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post();
                $cats = get_the_category(); ?>
                <?php if ($cats[0]->cat_name === 'Coaching') { ?>
                <div class="callout horizontal">

                    <?php the_post_thumbnail(); ?>

                    <div class="content">
                        <h5><?php the_title(); ?></h5>
                        <?php the_content(); ?>
                    </div>

                </div>
                <?php } ?>
            <?php endwhile; ?>

        <?php endif; ?>

上述代码仅用于显示Coaching类别中的类别。 但是,对于我的两个类别帖子会发生这种情况,但对于在“类别”下标记的其他三个帖子则不会

值得注意的是,我将wordpress设置中的阅读帖子设置为9999只是因为这是一个分页问题。

任何人都可以看到错误可能是什么。

我还想提一下,在我添加更多帖子之前,这个逻辑不是很久以前的工作。

干杯

**************更新***************

为了增加神秘感,我注意到这发生在网站的另一部分。 这与帖子无关。 但退出高级自定义字段。

编辑:

我现在已经看到你的帖子查询将返回所有帖子,你正在检查循环内的类别,这有点多余。 修改您的查询,如下所示:

$wpb_all_query = new WP_Query( 
                    array(
                        'post_type' => 'post',
                        'post_status' => 'publish',
                        'category_name' => 'coaching', //slug, not name!!
                        'posts_per_page' => 9999
                    )
                );

这将仅从该类别中提取帖子。 :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM