I have a loop inside a shortcode to display the list of posts for each category (schedule-day) in a custom post type (schedule).

The first category lists the posts in said category just fine, but the second category lists posts from both the first and second category.

Anyone experienced this issue before?

$terms = get_terms('schedule-day', 'hide_empty=1&orderby=name&order=ASC');
if(!empty($terms)) :

    $verytop = '<div class="tabs"><ul>';

      foreach($terms as $term) :

          $term_name = $term->slug;
          $args = array( 'post_type' => 'schedule', 'posts_per_page' => -1, 'schedule-day' => $term_name);
          $query = new WP_Query( $args );

          $top .= '<li><a href="#' . $term->slug . '">'.$term->name.'</a></li>';
          $close = '</ul>';

          if($query->have_posts()) : while ($query->have_posts()) : $query->the_post();   
            $next = '<div id="'.$term->slug.'" class="itinerary">';       
              $middle .= '<div class="schedule-item '.$term->slug.'" title="'.$term->slug.'"><div class="schedule_content"><h3>'. get_the_title() . '</h3>' . get_the_content() . '</div></div>';   
            $nexter = '</div>'; 
          endwhile; endif;

        $fish .= $next.$middle.$nexter;


          $verybottom = '</div>';
          return $verytop.$top.$close.$fish.$verybottom;
  • Each post has just one category? – Tomás Cot Sep 22 '14 at 23:53
  • Yes, I'm using the categories to break up the 'schedule' into days – user2585051 Sep 23 '14 at 0:02
  • possibly related to the use of an invalid character (hyphen) in the taxonomy name? From register_taxonomy: Name should only contain lowercase letters and the underscore character, and not be more than 32 characters long – Milo Sep 23 '14 at 0:16
  • Thanks Milo, I change the taxonomy name but that didn't solve the problem. – user2585051 Sep 23 '14 at 0:38
  • 2
    Could it be just due to the concatenation of some of the vars? $middle for example is never reset anywhere. – Welcher Sep 23 '14 at 1:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.