Support

Account

Home Forums General Issues Sort Custom Post Type by Taxonomy. Reply To: Sort Custom Post Type by Taxonomy.

  • 
    $products = get_field('products_in_this_auction', false false);
    $categories = get_terms('type_produc', 'orderby=count&order=DESC&hide_empty=1');
                          foreach( $categories as $category ): 
                          ?>
                          <h3 class="title_pru"><?php echo $category->name; // Prints the cat/taxonomy group title ?></h3>
                          <?php
                          $posts = get_posts(array(
    'post__in' => $products,
                          'post_type' => 'myproduct',
                          'taxonomy' => $category->taxonomy,
                          'term' => $category->slug,
                          'nopaging' => true,
                          ));
                          foreach($posts as $post): 
                          setup_postdata($post); 
                          ?>
                         
                          <div id="post-<?php the_ID(); ?>">
                         
                        
                        <?php  the_title( sprintf( '<p class="title_pru"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></p>' ); ?>
                         
                       
                         
                          </div><!-- #post-## --> 
                          <?php endforeach; ?>
                         
                         <?php endforeach; ?>