Created
April 22, 2012 20:25
-
-
Save ganicus/2466658 to your computer and use it in GitHub Desktop.
Wordpress: Tax-Terms Posts List
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div id="list123"> | |
| <?php | |
| // List posts by the terms for a custom taxonomy of any post type | |
| $post_type = 'YOUR_POST_TYPE'; | |
| $tax = 'YOUR_TAXONOMY'; | |
| $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="123breadcrumb">All <?php echo $tax; ?> Posts For <?php echo $tax_term->name; ?></h2> | |
| <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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment