0

When I go to Posts > Categories, some categories show that they have a post. See screenshot. But there are no posts linked to that category. When you click on that "1"-number, no posts are shown.

post categories

This is an issue because my blog page shows the category title and description even if there are no actual posts linked to that category (Wedge-system - see screenshot).

This is how I loop over all the categories and show the posts from that category:

<?php
$loop = new WP_Query( array(
                            'post_type' => 'Post',
                            'posts_per_page' => $post_per_page,
                            'tax_query' => array(
                                array(
                                    'taxonomy' => 'category',
                                    'field'    => 'id',
                                    'terms'    => array( $category->term_id ),
                                    'operator' => 'IN'
                                ),
                            ),
                        )
                        );
?>

<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    /* post template here */
<?php endwhile; wp_reset_query(); ?>
1
  • That post count number encompasses all post types using that term, not just the post type you're using to access that list in the admin. So if you don't have a post with that term, you have some other post type with that term, hence the 1. Yes, it is counter-intuitive.
    – vancoder
    Commented Apr 29, 2022 at 15:34

1 Answer 1

0

You're a post type that doesn't exist, there is no Post post type, did you mean post?


Sidenotes:

  • wp_reset_query is only for use after query_posts you should be using wp_reset_postdata instead.
  • There is no if ( $loop->have_posts() ) check so if no posts are found there is no message and it looks like the page is broken
  • This page would be much faster if you used category archives for your category archives, then used pre_get_posts to modify the query, instead of a page template and a brand new custom query
    • if you are doing this on category.php or archive.php then you're doubling the number of queries so that you can change posts_per_page, use pre_get_posts to change it instead

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.