WordPress.org

Ready to get started?Download WordPress

Forums

Multiple Custom Taxonomy Loops with No Duplicates (1 post)

  1. jh_dev35
    Member
    Posted 10 months ago #

    Hi all,

    A client wants a theme that, in short, has three buckets at the top that each lists 4 new posts from a particular custom taxonomy term (my taxonomy is called "verticals" and the terms are "news", "stories", "essays".

    This, I've accomplished, using this bit of code for each bucket.

    <?php
         $taxonomy = 'verticals'; // this is the name of the taxonomy
         $terms = get_terms( $taxonomy, 'showposts=5' ); // for more details refer to codex please.
         $args = array(
            'post_type' => 'post',
    		'posts_per_page' => '4',
    		'category__not_in' => '78',
            'tax_query' => array(
                        array(
                            'taxonomy' => 'verticals',
                            'field' => 'slug',
                            'terms' => 'news'
                        )
                    )
            );
    
         $my_query = new WP_Query( $args );
         if($my_query->have_posts()) :
             while ($my_query->have_posts()) : $my_query->the_post(); $cnt =0;?> 
    
    		 <?php $c++;
    if( $c == 1) :?>
    
    The content for my first posts
     <?php else :?>
                 Some slightly different content for each subsequent post.
     <?php endif;?>
     </div>
    
             <?php endwhile;?>
         <?php endif;
      ?>

    Now the problem is that the client then wants another section that pulls the 10 latest posts from all terms, but doesn't want this latter stream to duplicate any posts from any of the three buckets. Ideas?

Reply

You must log in to post.

About this Topic