• Hi
    I need a bit of help with automating my taxonomy.php template if possible. I’ve created a custom post type and a new taxonomy to go with it, I’ve then added some terms (categories) to it. What I want my taxonomy.php page to do is to show only the posts tagged with the current term to show on each page… so:

    Custom post type: Athletes
    Taxonomy: Sports
    Terms: Swimming, Athletics etc etc

    So when you go to …com/sports/swimming it shows all the posts from the athletes custom post type that are in the category swimming.

    This is the code I’d ideally like, capitals show the generated values required, depending if you are on swimming, or athletics page etc.

    <?php $args = array(
    	'post_type' => 'athletes',
    	'CURRENT_PAGE_TAXONOMY' => 'CURRENT_PAGE_TAXONOMY_TERM',
    	'posts_per_page' => -1
    );
    query_posts( $args );while ( have_posts() ) : the_post(); ?>

    Does anyone know a way to do this? I’ve tried a few versions of other peoples code, but just can’t get it to do what I need, I’m using

    <?php $term = $wp_query->queried_object;echo ''.$term->name.'';?>

    to show the page title correctly, but then need the relevant posts underneath..

    Help!

Viewing 1 replies (of 1 total)
  • Try this:

    Title:
    <?php single_cat_title( $prefix = '', $display = true ); ?>

    Query:

    <?php
    $current_query = $wp_query->query_vars;
    
    $wp_query = new WP_Query();
    $wp_query->query(array(
    	$current_query['taxonomy'] => $current_query['term'],
    	'paged' => $paged,
    	'posts_per_page' => 10,
    ));
    
    while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    //...Do Stuff...
    <?php endwhile;  wp_reset_postdata(); ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Using custom taxonomy with query_posts on taxonomy.php template’ is closed to new replies.