One query in a loop of queries does not return posts

enter image description here

I have a bunch of custom post types with a category and subcategory.

I have created a loop that goes through all the sub-categories for a given parent category ID, prints a Bootstrap column, and then into that column does a loop listing all the items (“services” here) tagged with that subcategory.

Works great, except for some reason I don’t understand, one subcategory does not print out any of its posts. I have double-checked, see not differences.

If I change the subcategory of the post, it shows in the new subcategory. But the one subcategory is always empty. I have tried changing to a default theme, etc. Same thing.

Here’s the code:

  <div id="business-systems" class="pillar">

      <h1 class="text-center">Business Systems</h1>

<div class="container-fluid">

  <div class="row services">
        $paged = ( get_query_var( 'paged' ) ) ? get_query_var('paged') : 1;
        $cat_id = 7;
            array( 'parent' => $cat_id )
        foreach ( $child_categories as $child ) { ?>
          <!-- loop through child categories and make columns -->
            <div class="col-sm-4">
                <?php echo $child ->cat_name; ?></h2>

              <?php  $args = array( 'post_type' =>
              'service', 'category_name' => $child->cat_name, 'posts_per_page' => -1, 'paged' => $paged, 'orderby' => 'title', 'order' => 'ASC'  );
                            $loop = new WP_Query( $args );
                            while ( $loop->have_posts() ) : $loop->the_post();
              <!-- contents of each service -->
                $link = get_field('link');
                if ($link) : ?>
                <a class="service-link" href="<?php echo $link; ?>">
              <?php endif; ?>
              <div class="home-service">
                <div class="home-service-title"><?php the_title(); ?></div>
                  <?php if( have_rows('icon_list') ): ?>
                    <div class="service-icons">
                      <?php while ( have_rows('icon_list') ) : the_row(); 
                      $image = get_sub_field('icon'); ?>
                      <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>">
                      <?php endwhile; ?>
              <?php else :
              // no rows found
              endif; ?>
          if ($link) : ?>
          <?php endif; ?>

          <?php endwhile; ?>
    <?php } ?>
    <?php wp_reset_query(); ?>

    <!-- end foreach loop --> </div>


As you can see here, the one subcategory is empty. I have tried renaming it so it’s not last, but it happens anyway.

Read more here:: One query in a loop of queries does not return posts

Leave a Reply

Your email address will not be published. Required fields are marked *