Loop for custom taxonomy
-
I have a custom post type (portfolio) with a custom taxonomy (genre) which is hierarchical. I’m trying to write a loop that displays all of the portfolios within a given genre. I have been working on this for days, and I can’t get anything to work. It seems like no matter what code I try, it always displays all of the portfolios in all of the genres, instead of being limited to one genre.
Here’s my latest version:
<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ), OBJECT, $term->name);
?>
<h2 class="genre-title"><?php
printf( __( '%s', 'comicpress' ), '<span>' . $term->name . '</span>' );
?></h2><div id="genre-content">
<div id="genre-thumbnails">
<?php $args = array( 'post_type' => 'portfolio', 'genres' => 'atomic-war-1' );
$loop = new WP_Query( $args );
?>
<?php
while ( $loop->have_posts() ) : $loop->the_post(); ?><div class="portfolio-item">
<?php the_post_thumbnail('thumbnail'); ?>
<div class="entry-content">
<h3 class="entry-title"><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php the_meta(); ?><?php echo get_the_term_list( $post->ID, 'genre', '<p>Genre: ', ', ', '</p>' ) ?>
</div><!-- .entry-content -->
</div><!-- .portfolio-item -->
<?php endwhile;?>
</div><!-- #genre-thumbnails -->
</div><!-- #genre-content -->This loop shows all of the portfolios in all genres, but I just want it to show portfolios in the genre “atomic-war-1.” Actually, eventually I want it to show all portfolios in the genre $term->name, but I’m trying to start out simple.
Any suggestions?
The topic ‘Loop for custom taxonomy’ is closed to new replies.