How do I use get_tag_link($tag_id); but with the tag slug? (6 posts)

  1. schmackLab
    Posted 5 years ago #

    I need something like this:

    <?php echo get_tag_link($tag_slug); ?>

    $tag_slug would be set with a custom field by the user.

    Is this possible?

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    Yes - it's possible. Have you read Using_Custom_Fields?

  3. schmackLab
    Posted 5 years ago #

    I understand custom fields the problem I'm having is using the tag slug. From my understanding only <?php echo get_tag_link($tag_id); ?>
    is supported.


  4. Michael
    Part-Time Forum Moderator
    Posted 5 years ago #


    <?php $tag_slug = get_post_meta($post->ID,'custom_key',true);
    $this_tag = get_term_by('slug',$tag_slug,'post_tag');
    if($this_tag) $tag_link = get_tag_link($this_tag->term_id);
  5. schmackLab
    Posted 5 years ago #

    Thanks this works great!

    Final code for anyone interested:

    <?php $tag_slug = get_post_meta($post->ID,'see_more',true);
    $this_tag = get_term_by('slug',$tag_slug,'post_tag');
    if($this_tag) $tag_link = get_tag_link($this_tag->term_id);?>
    <?php if (get_post_meta($post->ID, 'see_more', true)) { ?> See more from <?php the_title(); ?> right <a href="<?php echo $tag_link; ?>">here.</a><?php } ?>
  6. kaztheman
    Posted 4 years ago #

    Great! Thanks for your valuable info!

    I had the similar demand to yours. In my case I used the following code.

    <?php echo get_tag_link(get_term_by('slug','SLUGNAME','post_tag')->term_id); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic