Looping Through Categories of a CPT


I am trying to create tabs using the Foundations framework, outputting posts from a custom post type called testimonial and filtering them through their assigned custom category called filed-under. What am I doing wrong in my loop?

What I Have Working

  • Category tabs appear when new categories are created

What is Not Working

  • The posts aren’t appearing in the tabbed content area
  • How do you get the loop to filter the ‘all’ category?

Link to Demo


          // TABBED HEADERS
          echo '<ul class="tabs" data-tabs id="example-tabs">';
          echo '<li class="tabs-title is-active link-no-style">';
          echo '<a href="#all" aria-selected="true">All</a>';
          echo '</li>';
          $args = array(
            'hide_empty'=> 1,
            'orderby'   => 'name',
            'order'     => 'ASC',
            'post_type' => 'testimonial',
            'taxonomy'  => 'filed-under',
          $categories = get_categories($args);
          foreach($categories as $category) { 
              '<li class="tabs-title link-no-style">
                <a href="#' . $category->slug . '" aria-selected="true" role="tab" data-toggle="tab">    
          echo '</ul>';
          // TABBED CONTENT
          echo '<div class="tabs-content" data-tabs-content="example-tabs">';
          echo '<div class="tabs-panel is-active" id="' . $category->slug .'">';
          echo '<ul class="accordion" data-accordion data-allow-all-closed="true">';
          foreach($categories as $category) { 
            $the_query = new WP_Query(array(
              'post_type'     => 'testimonial',
              'post_status'   => ' publish',
              'category_name' => $category->slug,
          while ( $the_query->have_posts() ) : $the_query->the_post();
            echo '<li class="accordion-item" data-accordion-item>';
            echo '<a href="#" class="accordion-title">';
            echo '</a>';
            echo '<div class="accordion-content" data-tab-content>';
            echo the_field('testimonial'); 
            echo '</div>';
            echo '</li>';
          echo '</ul></div></div>';

  [1]: http://staging-newmummycompanyca.temp312.kinsta.cloud/testimonials/
Natasha Mcd 2 months 0 Answers 11 views 0

Leave an answer