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
Related posts:
- Tutorial: How to get image path on a post in Wordpress efficiently Wordpress did not provides a way to retrieve images on...
- Tutorial: How to get post id when using publish_post action hook in Wordpress Surprisingly, getting a ID when using a 'publish_post' action hook...
- Sorting post according to post tag in Wordpress Sorting post according to its post tag in Wordpress is...
- How To Exclude Page Permanently In Wordpress Without Using Any Plugin here is a way to permanently exclude pages globally across...
- Tutorial: How to validate whether a user has logged into Wordpress A simple explanation on what Wordpress plugin developer will need...











December 16th
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..
December 16th
no problem, glad it helps
January 17th
This only works inside the loop?
January 17th
nope. You can make this works outside the loop but this is how i did it within the loop.
January 18th
And it does work! Thanks! It’s weird that WP api mentions it only works from within the loop.