简体   繁体   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; ?>

The above code is meant to only show categories that are from the category Coaching. 上述代码仅用于显示Coaching类别中的类别。 However this happens for two of my category posts but not for the other three that are labeled under Category. 但是,对于我的两个类别帖子会发生这种情况,但对于在“类别”下标记的其他三个帖子则不会

It is worth noting that I have set my reading posts in the wordpress settings to 9999 just incase this was a pagination problem. 值得注意的是,我将wordpress设置中的阅读帖子设置为9999只是因为这是一个分页问题。

Can anyone see what the error might be. 任何人都可以看到错误可能是什么。

I would like to also mention that this logic was working not so long ago before I added a lot more posts. 我还想提一下,在我添加更多帖子之前,这个逻辑不是很久以前的工作。

Cheers 干杯

************** UPDATE *************** **************更新***************

To add to the mystery I have noticed that this is happening on another part of the site. 为了增加神秘感,我注意到这发生在网站的另一部分。 Thats isn't related to the posts. 这与帖子无关。 But pulling out from Advanced Custom Fields. 但退出高级自定义字段。

EDIT: 编辑:

I've seen now that your post query will return all posts, and you're checking for category inside the loop, which is kinda redundant. 我现在已经看到你的帖子查询将返回所有帖子,你正在检查循环内的类别,这有点多余。 Modify your query like this: 修改您的查询,如下所示:

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

This will pull only posts from that category. 这将仅从该类别中提取帖子。 :) :)

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

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