WordPress.org

Ready to get started?Download WordPress

Forums

Get tag slug (3 posts)

  1. Darran
    Member
    Posted 6 years ago #

    Is there a way I can retrieve a tag slug from a tag title?

    I need to use the tag slug to retrieve the query post because it does not accept the tag title. Can anyone help with getting the tag slug?

  2. Darran
    Member
    Posted 6 years ago #

    Anyone at all?

  3. Mikko Saari
    Member
    Posted 6 years ago #

    I've been fighting with the same problem. I did come up with a solution, but it's slightly ugly: check the db. Here's a function I wrote to do the trick:

    function mikko_get_tag_slug($title) {
    	global $wpdb;
    	$slug = $wpdb->get_var("SELECT slug FROM $wpdb->terms WHERE name='$title'");
    	return $slug;
    }

    Then I just

    <?php
    $slug = mikko_get_tag_slug(single_tag_title('', false));
    query_posts('tag=' . $slug); ?>

    in the template code.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags