Show all custom post types organized by custom taxonomy
-
I’m building a wordpress powered site for a theatre company. I’m using the types plugin and have created a custom post type ‘productions’ and organizing them by a custom taxonomy ‘seasons.’ I’m building a custom template for a page that should display every show organized by season. I’ve tried many things and still can’t get it to work. Here’s the code I’m using now. Any help is appreciated!
<?php //get all seasons then display all posts in each term $taxonomy = 'seasons'; $term_args=array( 'orderby' => 'name', 'order' => 'ASC' ); $terms = get_terms($taxonomy,$term_args); if ($terms) { foreach( $terms as $term ) { $args=array( 'tax_query' => array( array( 'taxonomy' => 'seasons', 'field' => 'slug', 'terms' => array($term->term_id) ) ) ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { ?> <div class="season section"> <h2><?php echo $term_name; ?></h2> <ul> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> <li> <a style="background-image: url( <?php //Get the Thumbnail URL $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 300,160 ), false, '' ); echo $src[0]; ?> );" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <div class="inner-block" <h3><?php the_title(); ?></h3> <span class="playwright"><?php echo(types_render_field("playwright", array("raw"=>"true"))); ?></span> <span class="director"><?php echo(types_render_field("director", array("raw"=>"true"))); ?></span> <span class="dates"><?php echo(types_render_field("date", array("style"=>"text"))); ?></span> </div> </a> </li> <?php endwhile; ?> </ul> </div> <?php } } } wp_reset_query(); // Restore global post data stomped by the_post(). ?>
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Show all custom post types organized by custom taxonomy’ is closed to new replies.