I'm using a WP plugin Called Search and Filter to filter a custom post type — a user directory.

The plugin lets a user filter the directory by specifying terms.

It will also let a user filter the directoy by MULTIPLE terms.

When it does so, I get a slug constructed like this:


Posts are returned via the taxonomy.php page.

First, I didn't even know you could do this, so that's cool.

But my question is, how do I display the second term in the slug query?

In other words, I can get the taxonomy.php page to display the term "Chiefs of Protocol" with single_term_title().

But how can I get WordPress to display the second term which is queried in the slug — in this case "United States of America"?

2 Answers 2


Try to get the value of querystring

$country = $_GET['country'];
  • That certainly does return the querystring — but how can I get the friendly name of that term? IE, this returns "united-states-of-america", which is the slug for that term.
    – Tomasch
    Jul 10, 2016 at 18:40

You've got the slug of the term in the query string, so you can use the get_term_by() function to get the term object. For example, assuming your taxonomy name is 'dir-type':

$country = get_term_by( 'slug', $_GET['country'], 'dir-type' );

Using that, you can then print out information from the term object like this:

echo $country->name; // print the name
print_r( $country ); // print all available properties (for debugging purposes)

The first line there will show the name; the second will show you the rest of the information stored in the term object (just for your interest!)

  • Well, that looked great but I can only get the slug to return. After running get_term_by, everything else fails.
    – Tomasch
    Jul 12, 2016 at 1:00
  • @Tomasch Oops, I forgot to include the taxonomy parameter - it's required (in all cases but one, and certainly in this case). Assuming your taxonomy is called 'dir-type', try that updated code now.
    – Tim Malone
    Jul 12, 2016 at 1:05
  • @Tomasch Also, if it fails again, please explain what's happening - i.e. error messages, etc. 'Everything else fails' isn't a helpful error description. If you aren't getting errors when something goes wrong, make sure WP_DEBUG is turned on.
    – Tim Malone
    Jul 12, 2016 at 1:06
  • Well, that just opens another can of works. It looks like we might have an error in Custom Post Type UI — the plugin I'm using for custom post types. I get this error, abbreviated: ` Warning: Cannot modify header information - headers already sent by (output started at /home/content/c/t/s/ctsgraphics/html/_ccc/wp-content/plugins/custom-post-type-ui/custom-post-type-ui.php:471) in /home/content/c/t/s/ctsgraphics/html/_ccc/wp-includes/pluggable.php on line 1167`
    – Tomasch
    Jul 12, 2016 at 1:22
  • @Tomasch Hmm I can't really help with that, as I don't know the plugin. You could see if there are any updates available for it, contact the author, or drop it and create the post types yourself using register_post_type(). Alternatively, the error might not be a fatal one and you might be able to still use it fine.
    – Tim Malone
    Jul 12, 2016 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.