List custom post type by Custom Taxonomy
-
Hi,
I have created a custom post type ‘merchants’ and a custom taxonomy ‘industry’ for use with the custom post type.
I now need to list all the taxonomy terms, and show the post title, as well as excerpts + first image in the post.
THis is what I have so far,
<div class="itembox"> <h1>Merchants Directory</h1> <div class="itemboxinner"> <div id="content-main"> <?php // List posts by the terms for a custom taxonomy of any post type $post_type = 'merchants'; $tax = 'industry'; $tax_terms = get_terms( $tax ); if ($tax_terms) { foreach ($tax_terms as $tax_term) { $args = array( 'post_type' => $post_type, "$tax" => $tax_term->slug, '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() ) : ?> <h2 class="breadcrumb"><span style='font-size: 20px;color: #006400'> All <?php echo $tax; ?> Posts For <?php echo $tax_term->name; ?></h2></span> <ul class="taxlist"> <?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?> <li id="post-<?php the_ID(); ?>"> <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> </li> <?php endwhile; // end of loop ?> </ul> <?php else : ?> <?php endif; // if have_posts() wp_reset_query(); } // end foreach #tax_terms } ?> </div>and the output is:
<img src=”http://i48.photobucket.com/albums/f233/yemitubosun/ouuput.png” border=”0″ alt=”Photobucket”>I am struggling with the code.
Please help correct the code to
1.list the taxonomy terms,
2.the posts under each term,
3.Excerpts of each post.
4.First image in the post.Thank you
The topic ‘List custom post type by Custom Taxonomy’ is closed to new replies.