Title: Automatic post title loop in taxonomy.php
Last modified: August 19, 2016

---

# Automatic post title loop in taxonomy.php

 *  Anonymous User
 * (@anonymized-473288)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/automatic-post-title-loop-in-taxonomyphp/)
 * Many thanks to Justin Tadlock for posting the following piece of code in the 
   post [Using custom taxonomies to create a movie database](http://justintadlock.com/archives/2009/06/04/using-custom-taxonomies-to-create-a-movie-database):
 *     ```
       $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
       ```
   
 * It helped me in writing the following bit of code (subject to review). The code
   will automatically show the posts for whatever custom taxonomy term page one 
   is on. In order to have an automatic loop in taxonomy.php it appears that one
   might be able to do the following:
 *     ```
       <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>              
   
       <?php query_posts( array($term->taxonomy => $term->name) ); ?>
   
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
   
       <?php the_title(); ?>
   
       <?php the_excerpt(); ?>
   
       <?php endwhile; else: ?>
   
       <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
   
       <?php endif; ?>
       ```
   
 * Is there anything in the code that needs to be improved?

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Justin Tadlock](https://wordpress.org/support/users/greenshady/)
 * (@greenshady)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/automatic-post-title-loop-in-taxonomyphp/#post-1286325)
 * You don’t need these two lines:
 *     ```
       <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>              
   
       <?php query_posts( array($term->taxonomy => $term->name) ); ?>
       ```
   
 *  [liove](https://wordpress.org/support/users/liove/)
 * (@liove)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/automatic-post-title-loop-in-taxonomyphp/#post-1286352)
 * query_posts does not work for me with my tanonomy.php template.
    Why? Can you
   help?
 *  [liove](https://wordpress.org/support/users/liove/)
 * (@liove)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/automatic-post-title-loop-in-taxonomyphp/#post-1286353)
 * here’s my exemple : [http://www.insas.be/realisation/natalia-duque/](http://www.insas.be/realisation/natalia-duque/)
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/automatic-post-title-loop-in-taxonomyphp/#post-1286354)
 * it might help if you can copy the code of our taxonomy.php into a [pastebin ](http://wordpress.pastebin.com/)
   and post the link here.
    otherwise – what is there to guess from an example showing
   a nearly empty page?
 *  [avenueverve](https://wordpress.org/support/users/avenueverve/)
 * (@avenueverve)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/automatic-post-title-loop-in-taxonomyphp/#post-1286370)
 * Here is a pasteable piece of code to get the taxonomy title for taxonomy.php 
   template.
 *     ```
       <?php
       $term  = $wp_query->query_vars["term"];
       $tax 	= $wp_query->query_vars["taxonomy"];
       $title  = get_term_by( 'slug', get_query_var( $term ), get_query_var( $tax ) );
       ?>
       ```
   

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Automatic post title loop in taxonomy.php’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 5 participants
 * Last reply from: [avenueverve](https://wordpress.org/support/users/avenueverve/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/automatic-post-title-loop-in-taxonomyphp/#post-1286370)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
