Support » Fixing WordPress » Multiple Custom Post Type taxonomy terms loops – how?

  • Resolved flint_and_tinder

    (@flint_and_tinder)


    Hi all,

    I’ve set up a CPT called ‘fan’ and made a taxonomy for it called ‘fan_post_types’. Within that taxonomy I have two terms called ‘fan-comment’ and ‘fan-merchandise’.

    What I am trying to do now is set up a page called ‘fans’ and include 2 loops within it, one for the posts of both taxonomy terms so I have a feed of each.

    I’m using WP_query loops at the moment, but I can’t get them to work. Both loops show posts from both taxonomy terms, instead of one loop showing one set and the other loops displaying the rest. Can anybody help please?

    Here is my current code:
    http://wordpress.pastebin.ca/2148417

    I’m pulling my hair out here. Why do custom post type taxonomies have to be so complicated? 🙁

    Many thanks,

    Adam.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter flint_and_tinder

    (@flint_and_tinder)

    A-ha, I have solved it myself. Thanks anyway to anyone who reads this.

    Can you post your solution for others?

    Thread Starter flint_and_tinder

    (@flint_and_tinder)

    Hi Chris,

    I managed it like the below (which I think is similar to the original paste bin code, but without slight errors), for each loop in the template you just need something like the following. This example is for the fan-comments loop. For the fan-merchandise loop I changed the term field and $comments identifiers to suit.

    <?php $args=array(
    	'taxonomy' => 'fan_post_types',
    	'term' => 'fan-comments',
    	'post_type' => 'fan',
    	'posts_per_page' => 8
    	);
    	$comments = new WP_Query($args);
        if($comments->have_posts()) : while($comments->have_posts()) :
    	$comments->the_post(); ?>
    
    Whatever you want to display goes here...
    
      <?php endwhile; endif; ?>
      <?php wp_reset_query(); // end Fan Cooments loop. ?>

    Let me know if you need any more info than that.

    Thread Starter flint_and_tinder

    (@flint_and_tinder)

    Second loop:

    <?php $args=array(
    	'taxonomy' => 'fan_post_types',
    	'term' => 'fan-merchandise',
    	'post_type' => 'fan',
    	'posts_per_page' => 8
    	);
        $merchandise = new WP_Query($args);
        if($merchandise->have_posts()) : while($merchandise->have_posts()) :
    	$merchandise->the_post(); ?>
    
    Whatever you want to display goes here...    	
    
      <?php endwhile; endif; ?>
      <?php wp_reset_query(); // end Fans Merchandise loop. ?>
    Thread Starter flint_and_tinder

    (@flint_and_tinder)

    Both those loops site within the main page loop like so…

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <?php the_content(); ?>
    
    Loop 1
    
    Loop 2
    
    <?php endwhile; endif; ?>

    Thank you! This worked for me.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Multiple Custom Post Type taxonomy terms loops – how?’ is closed to new replies.