skip to Main Content

I wanted to fetch the TAG Name with Tag ID, I tried it using get_tag() function but it doesn’t print anything.

<?php
$certification = get_tag(13);
echo $certification->name; ?>

As I checked there is a Tag available in my wordpress with ID 13

can someone help to fix?

3

Answers


  1. You can try this code –

    $tag_id = get_term_by('id', 13, 'post_tag');
    echo $tag_id->name;
    
    Login or Signup to reply.
  2. $post_tags = get_the_tags($id); //your tagid
    if ( $post_tags ) {
        echo $post_tags[0]->name; 
    }
    
    Login or Signup to reply.
  3. You can use this code for getting the term name by id

    $term = get_term( 13, 'post_tag' );
    echo $term->name;
    

    Hope it will work as I have tried it and working perfectly.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search