WordPress.org

Ready to get started?Download WordPress

Forums

Query Multiple Taxonomies
[resolved] summarize taxonomies in title (12 posts)

  1. johnklijnen
    Member
    Posted 3 years ago #

    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; ?>
    </h2>

    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.

  2. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    You can use this:

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

  3. johnklijnen
    Member
    Posted 3 years ago #

    Yes!!
    Scribu, You are the best!

  4. Mr. Shiv
    Member
    Posted 3 years ago #

    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 } ?>
  5. Mr. Shiv
    Member
    Posted 3 years ago #

    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 } ?>
  6. itsbarry
    Member
    Posted 3 years ago #

    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?

  7. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    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 } ?>
  8. itsbarry
    Member
    Posted 3 years ago #

    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.

  9. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    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.

  10. mark7694
    Member
    Posted 2 years ago #

    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: http://www.dmngoodstaging.com/alliance/resource-library/?content-type=community-plans&topic-area=outreach&geographic-location=&state=

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

    Is this possible?

  11. mark7694
    Member
    Posted 2 years ago #

    Disregard. Got this to work.

  12. paa1605
    Member
    Posted 2 years ago #

    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

    /category_name=clothes&colour=reds&designer=nike

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

    Is this possible? Thanks

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic