Get Tag With Post ID In WordPress

Today i was writing my plugin and required each post tag to be placed into a variable outside of WordPress loop. I have a look at WordPress function reference api and did some Google and surprisingly i couldn’t find it. After a long time of digging on Google, i finally found a clue. Apparently, the method get_the_tags takes in a post id! However, if you look at get_the_tags reference page, it doesn’t mention at all. Hence, i decides to write it down here to ease people life in the future.

Get Tag In WordPress

Once you get hold of your Post ID you can easily retrieve the tag associated with the post with the following code.

                        $postid = $post->ID;
                        get_the_tags($postid);

It will return a list of tags. Hope it helps icon smile Get Tag With Post ID In Wordpress

 

Like this post? Share it!

digg 48 Get Tag With Post ID In Wordpress reddit 48 Get Tag With Post ID In Wordpress stumbleupon 48 Get Tag With Post ID In Wordpress delicious 48 Get Tag With Post ID In Wordpress furl 48 Get Tag With Post ID In Wordpress technorati 48 Get Tag With Post ID In Wordpress google 48 Get Tag With Post ID In Wordpress myspace 48 Get Tag With Post ID In Wordpress facebook 48 Get Tag With Post ID In Wordpress twitter 48 Get Tag With Post ID In Wordpress
share save 171 16 Get Tag With Post ID In Wordpress

No related posts.

About Clay

I am Clay who is the main writer for this website. I own a small web hosting company in Malaysia and i'm available to be hired as individual contractor on elance or odesk. You can find me on twitter.
This entry was posted in How-to, Others and tagged . Bookmark the permalink.

5 Responses to Get Tag With Post ID In WordPress

  1. Peter says:

    Thanks for posting this – I can never seem to find this function when I need it. It would help if the codex was a little more clear..

  2. Clay says:

    no problem, glad it helps :)

  3. Daniel says:

    This only works inside the loop?

  4. Clay says:

    nope. You can make this works outside the loop but this is how i did it within the loop.

  5. Daniel says:

    And it does work! Thanks! It’s weird that WP api mentions it only works from within the loop.