Support » Fixing WordPress » WP Showing Posts Inconsistency in Categories

  • Dashboard-> Posts-> Categories

    There is a category which says the Post Count = 3.

    I click the ‘3’ to view the posts but I get No posts found.

    Not all categories are like this – There are other categories that show Posts that match the count displayed. Just a few rogue categories. Is there any reason that a category could show ‘3’ on the categories page but ‘0’ in the Posts list?

Viewing 1 replies (of 1 total)
  • Have same issue, some categories show posts some not. Do not know why, but have_posts() from categories.php returns false. Here is follow code that you can put to the category.php template:

    echo '<pre style="background: #eee;padding: 1rem;">Debug' . PHP_EOL;
    echo 'have_posts() = ' . var_export(have_posts(), true) . PHP_EOL;
    $category = get_queried_object();
    $args = [
    	'post_type' => 'post',
    	'tax_query' => [
    			'taxonomy' => 'category',
    			'field' => 'term_id',
    			'terms' => $category->term_id,
    $query = new WP_Query($args);
    if ($query->have_posts()) {
    	while ($query->have_posts()) {
    		printf('> %s (id=%d)' . PHP_EOL, get_the_title(), get_the_ID());
    echo '</pre>';
    • This reply was modified 6 months, 2 weeks ago by OzzyCzech.
Viewing 1 replies (of 1 total)
  • The topic ‘WP Showing Posts Inconsistency in Categories’ is closed to new replies.