WordPress.org

Ready to get started?Download WordPress

Forums

Get Tag Slug in single.php (5 posts)

  1. gamerusage01
    Member
    Posted 1 year ago #

    I am pulling my hair on this one, hopefully someone can help me.

    I have looked everywhere and can not find a function/get that will grab the tag slug of the current post I am viewing.

    The reason why I need this is because I have content in tabs that will get loaded on tags.

    Example:

    I currently have on tag on a post. I want to grab the tag slug (Tag would be called The: Show and the slug would be the-show.

    The slug is what I need. Thanks for your help.

  2. IMICreation
    Member
    Posted 1 year ago #

    <?php $tags = get_the_tags(get_the_id()); foreach($tags as $tag) { echo $tag->slug; } ?>
    put this code in your loop

  3. gamerusage01
    Member
    Posted 1 year ago #

    Code works great. Only problem is that the code will be going into a <?php function so it needs to be converted.

    I don't know the exact way/term but it involves removing the <?php and the ?> being replaced by .' and '.

  4. gamerusage01
    Member
    Posted 1 year ago #

    should note that this will be going in the query_posts function (tag= specifically)

  5. gamerusage01
    Member
    Posted 1 year ago #

    never mind. I figured it out. For those that want to know for future cases:

    <?php $tags = get_the_tags(get_the_id()); foreach($tags as $tag) ?>
    <?php query_posts('cat=23&tag='.$tag->slug.'&showposts=3&posts_per_page=3&paged=' . get_query_var('paged') ); while (have_posts()) : the_post(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic