Support » Plugin: Query Multiple Taxonomies » [Plugin: Query Multiple Taxonomies] summarize taxonomies in title

  • Resolved johnklijnen


    Is it possible to list the selection of multiple taxonomies in the title of the archive.php? I’m using this at the moment:

    <h2>You selected:
    <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?>

    But this only shows the last taxonomy selected. I want to show the complete list of selected taxonomies. Is it possible? And if so, please help me.
    Thanks, john.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author scribu


    You can use this:

    <?php echo QMT_Template::get_title(); ?>

    Scribu, You are the best!

    Here’s how I did it:

    <?php if (is_multitax()) {
    	foreach ( qmt_get_query() as $tax => $slug ) {
    		$terms[] = get_term_by( 'slug', $slug, $tax )->name;
    	} ?>
    	<h1 class="pagetitle">Updates filtered on <?php echo implode( ", ", $terms ); ?></h1>
    <?php } ?>

    The code in my previous post ignores the taxonomy titles, but those would be easy to add via something like:

    <?php if (is_multitax()) {
    	foreach ( qmt_get_query() as $tax => $slug ) {
    		$terms[] = get_taxonomy( $tax )->label . ': ' . get_term_by( 'slug', $slug, $tax )->name;
    	} ?>
    	<h1 class="pagetitle">Updates filtered on <?php echo implode( ", ", $terms ); ?></h1>
    <?php } ?>

    Mr. Shiv’s way displays the title nicely, as the taxonomy label. But the code is a little more verbose.

    Scribu, do you have a way to display the label in one compact echo statement?

    Plugin Author scribu


    With the development version (1.4.1-alpha), you can use QMT_Template::get_title(), which will also handle tax=foo+bar:

    <?php if (is_multitax()) { ?>
    	<h1 class="pagetitle">Updates filtered on <?php echo QMT_Template::get_title(); ?></h1>
    <?php } ?>

    Thanks scribu. I did understand your original example, and it worked perfectly for me. I like that it’s a very short elegant statement.

    However, when I use QMT_Template::get_title() I get the taxonomy name that is used internally by WordPress. As you know that is different from the public-facing label, or slug.

    I would like it if there were a similar brief statement for displaying the slug. I’m using Shiv’s method for now, which works great but requires a little more code to extract that array value.

    Plugin Author scribu


    You seem to be confusing ‘taxonomy’ with ‘term’ and ‘label’ with ‘slug’.

    No version of the plugin ever displayed the raw taxonomy name.

    What’s more, the dev version actually uses the singular_name label if there’s only one term being queried, so you get something like this:

    Color: red

    Colors: red + green

    Also, the dev version displays the term name instead of the slug, which is actually what you want. The slug is what you see in the URL: /sometax/some-term while the name can be pretty, like Some Term.

    When I do a search and the archive returns all of the posts, the snippet <?php echo QMT_Template::get_title(); ?> works perfectly. However, once I click on a post I would like to be able to list all of the terms that that post is grouped under in the postmeta area much like tags work.

    For example, after choosing two terms from the dropdown it lists this result: View here:

    But once I click the entry I am unable to show the terms.

    Is this possible?

    Disregard. Got this to work.

    Great plug-in Scribu!

    Is it possible to display only certain terms from the slug and not all of them in a title? If i use the examples above it returns all the queries. For example, if my slug was


    i would just like to output the category_name of ‘clothes’ as a title.

    Is this possible? Thanks

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Plugin: Query Multiple Taxonomies] summarize taxonomies in title’ is closed to new replies.