Support » Fixing WordPress » Passing queried taxonomy

  • I hope I’m posting this in the right forum…

    In my theme, I created a page that lists all terms from a taxonomy, this then links to a page that displays all posts of that taxonomy, each item is then linked to their respective post. The taxonomy template uses <?php single_term_title(''); ?> to display the queried taxonomy term name. How can I pass that queried taxonomy term to the single page template to then be used?

    I tried using the <?php single_term_title(''); ?> but that didn’t seem to work. I’m sure it’s a simple bit of code, but I can’t find it in all my searching.

    Additional information
    This is for a custom post type, “Services” with custom taxonomy, “Locations”.

    Here’s the part that lists my taxonomies:

        $terms = get_terms('locations');
            $temp = '';
        foreach($terms as $term):
            $title = $term->name;
            $first_letter_lower = strtolower(substr($title, 0, 1));
            if($temp != $first_letter_lower){
                echo '<div class="locations-'.$first_letter_lower.'">';
                $temp = $first_letter_lower;
            $first_letter = strtoupper(substr($title, 0, 1));
            if($temp != $first_letter){
                echo '<h3>'.$first_letter.'</h3><hr />';
                $temp = $first_letter;
        <li><a href="<?php echo get_term_link($term);?>"><?php echo $term->name ;?></a></li>
    <?php endforeach;?>

    Here’s the part for the taxonomy page template:

    <?php if ( have_posts() ) : ?>
        <header class="archive-header">
            <h1 class="archive-title">
                <?php single_term_title('Services in '); ?>
        </header><!-- .archive-header -->
        <?php while ( have_posts() ) : the_post();?>
                <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'twentytwelve' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
        <?php endwhile;?>
    <?php else : ?>
        <?php get_template_part( 'content', 'none' ); ?>
    <?php endif; ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • <?php echo single_tag_title(); ?>


    <?php echo single_cat_title(); ?>

    The problem with that solution is that each post is assigned to multiple taxonomy terms. So using <?php echo single_tag_title(); ?> just returns all taxonomy terms of that post.

    I’l like to just reference the one taxonomy term that was clicked on from the get go.

    To get a better idea, take a look at my example:

    If you were to click on “Abbott, CA” (which is a taxonomy term), you are then taken to my page template taxonomy-locations.php and are shown all posts in that taxonomy term “Abbott, CA”. Clicking any post takes you to the single-services.php. In that ‘single-services.php`, I’d like to reference the queried taxonomy term…so in this case I want to display “Abbott, CA”.

    Hope that helps make more sense.

    A single page doesn’t know what you clicked to get there. You’ll have to save that information temporarily in a transient or pass that information in the url. You can use a custom query variable.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Passing queried taxonomy’ is closed to new replies.