Return to Snippet

Revision: 54713
at January 9, 2012 07:06 by dolbex


Initial Code
//for a given post type, return all
	  $post_type = 'energy-link';
	  $tax = 'category';
	  $tax_terms = get_terms($tax);
	  if ($tax_terms) {
		foreach ($tax_terms as $tax_term) {
			echo '
			<div class="wrap_the_tax">
			';
			
			$args=array(
				'post_type' => $post_type,
				'tax_query' => array(
					array(
						'taxonomy' => $tax,
						'field' => 'slug',
						'terms' => $tax_term->slug
					)
				),
				'post_status' => 'publish',
				'posts_per_page' => -1,
				'orderby' => 'title',
				'order' => 'ASC',
				'operator' => 'IN'
			); // END $args

			$my_query = null;
			$my_query = new WP_Query($args);
			
			//debug($my_query);
			
			if( $my_query->have_posts() ) {			
				while ($my_query->have_posts()) : $my_query->the_post(); 
				  echo sces_smallblock( $post->post_title,  $post->post_excerpt); 
				endwhile;
			} // END if have_posts loop
			wp_reset_query();
			echo '
			</div>
		  ';
		} // END foreach $tax_terms
	} // END if $tax_terms

Initial URL

                                

Initial Description
Wordpress 3.3 custom post type query that will get all of the taxonomies, loop through them, and output the posts from each.

Initial Title
Loop through Wordpress 3.0+ custom post type taxonomies

Initial Tags
wordpress

Initial Language
PHP