• How can i list a custom post type but show them grouped by their taxonomy?
    I know how to show the CPT but I can’t figure out how to output the cpt per taxonomy.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I have the exact same problem and I’ve been searching for days now. Can’t seem to find anything.

    I get the post type to use the taxonomy.php but when I want to use the menu (which is using the CPT:s hierarchical custom taxonomy) to go from Parent cat -> subCat1 or subCat2 and so on. It displays all post all the time.

    So, I wan’t my post type to work like the default post type works.

    Any help would be very appreciated!
    Thanks!

    Thread Starter slee

    (@slee)

    Hi osby here is the code I used:

    $post_type = 'post_type_name';
    $tax = 'taxonomy_name';
    $tax_terms = get_terms($tax);
    if ($tax_terms) {
      foreach ($tax_terms  as $tax_term) {
        $args=array(
          'post_type' => $post_type,
          "$tax" => $tax_term->slug,
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'caller_get_posts'=> 1
        );
    
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo '<h3 class="divisions">'. $tax_term->name . '</h3>';
    	  echo '<ul class="team-members">';
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
             <li>
             <h4 class="team-member"><?php the_title(); ?></h4>
             <?php if(has_post_thumbnail()) { ?>
            <span class="alignleft"><?php the_post_thumbnail(); ?></span>
            <?php } the_content(); ?>
            </li>
            <?php
          endwhile;
    	  echo '</ul>';
        }
        wp_reset_query();
      }
    }

    I hope this helps ??

    Big thanks to you! I finally got mine working to.

    Great!

    since 3.1 the way you query taxonomy has changed so for anyone stumbling across this code like i did today here is the amended code:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    enjoy

    S

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘list custom post type by taxonomy’ is closed to new replies.