• I’m using a variation of Michael H’s great code to produce a list of wines organized by region:

    <?php
    $args=array(
      'region' => 'loire-valley',
      'post_type' => 'producers',
      '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 'Loire Valley';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <?php query_posts($query_string . '&orderby=name&order=ASC'); ?>
    	<?php get_template_part( 'content-archive' ); ?>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    But I have five regions (Loire Valley, Southwest, Burgundy, Rhone Valley, Champagne). Is there any way to automate the above so I don’t have to copy and paste it five times with each region listed?

    In other words how can I make the $args variable cycle through all five regions and list their respective post types, in the manner above?

Viewing 1 replies (of 1 total)
  • Thread Starter dgissen

    (@dgissen)

    Ok; figured that out too (see above and code below) to output archive for taxonomy ‘region’ and post type ‘producers’. Just replace those terms and you’re good to go.

    Any idea how I can have a link to the taxonomy archive for the echo $term-> name ?

    <?php $terms = get_terms('region');
    
    $count = count($terms);
    
     if ( $count > 0 )
     { foreach ( $terms as $term )
     {
    $args=array(
      'region' => $term->name,
      'post_type' => 'producers',
      'post_status' => 'publish',
      'orderby'=>'title',
      'order'=>'ASC',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo $term->name;
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
    	<?php get_template_part( 'content-archive' ); ?>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    
     }
     }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘custom taxonomy query – again…’ is closed to new replies.