WordPress.org

Ready to get started?Download WordPress

Forums

can't get tags of post ... (3 posts)

  1. a42
    Member
    Posted 1 month ago #

    Hi there

    I trying to get tags of a post and have tried :

    $t = get_the_tags($post_id);
    print_r($t);

    and

    $tags = wp_get_post_tags($post->ID);
    
    if ($tags) {
      foreach($ags as $tag) {
        echo $tag->name;
      }
    }

    doesn't return anything...

    What else can I do ?

    Cheers
    Adam

  2. Steven Jones
    Member
    Posted 1 month ago #

    Is the $post variable available at the time you call this?

    Try adding

    global $post

    before you do the wp_get_post_tags().

    Alternatively you can just use the function the_tags()

    http://codex.wordpress.org/Function_Reference/the_tags

  3. a42
    Member
    Posted 1 month ago #

    Hi Steven

    Yes I do call the $post (it's inside a loop I try to get the tags)

    If I use the function the_tags() I get nothing... (?)

    Cheers,
    Adam

Reply

You must log in to post.

About this Topic

Tags