WordPress.org

Forums

HELP - Trying to display Taxonomy and children (2 posts)

  1. pixelnate
    Member
    Posted 4 years ago #

    I am trying to display all the 'Induction Years' and posts (inductees) associated with that induction year. But what I have rendering is each induction year and underneath it every post that has an induction year, not just the ones with that specific year. Can somebody help me out here?

    This is the code I am using:

    <?php
    //get terms (e.g. categories or post tags), then display all posts in each retrieved term
    $taxonomy = 'induction_year';//  e.g. post_tag, category
    $current_cat = get_query_var('induction_year');
    $param_type = 'induction_year__in'; //  e.g. tag__in, category__in
    $term_args=array(
      'orderby' => 'name',
      'order' => 'ASC',
      'child_of' => get_query_var('induction_year')
    );
    $terms = get_terms($taxonomy,$term_args);
    if ($terms) {
      foreach( $terms as $term ) {
        $args=array(
          $param_type => array($term->term_id),
          'post_type' => 'inductee',
          'post_status' => 'publish',
          'showposts' => -1,
          'caller_get_posts'=> 1,
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
    
          echo '<h4>' . $term->name. '</h4> '; // Sub-Category Title
    
          while ($my_query->have_posts()) : $my_query->the_post(); // Post Contents ?>
    				<?php the_title(); ?>
    
    		<?php endwhile;
        }
      }
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  2. pixelnate
    Member
    Posted 4 years ago #

    bump.

Topic Closed

This topic has been closed to new replies.

About this Topic