• Resolved jwrbloom

    (@jwrbloom)


    I’m either not understanding what I’m finding in search or not applying what I read correctly, but I’m trying to get the slug and use it to get a match in a query.

    Right now I’m using:
    $tag = single_tag_title(“”, false);

    However, the gets me the title of the term, which has some issues with apostrophes. I’d like to just get the slug.

    I’ve tried get_term and get_terms_by, but they don’t work, or I’m not using them correctly.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    What term are you trying to get? single_tag_title() gets the tag name of the current tag archive page. You are correct, titles are less than useful due to apostrophes, spaces, special chars, etc. Using a term slug instead is a good call. Maybe even better is to use the term ID. It can be used in most queries where you could use a term slug. Using IDs in queries are generally more efficient FWIW.

    To get the current tag archive’s term ID, use get_queried_object_id(). If you want the slug instead, you can do get_queried_object()->slug

    Thread Starter jwrbloom

    (@jwrbloom)

    Yeah, I found an example using get_queried_object(). I set a variable to it, then went $tag->slug.

    Thank you for replying though.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Getting/using the slug of taxonomy…’ is closed to new replies.