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:
- Sorting post according to post tag in Wordpress Sorting post according to its post tag in Wordpress is...
- Wordpress Template_page meta key and update_post_meta A simpel article to help people who are having difficulty...
- How To Exclude Page Permanently In Wordpress Without Using Any Plugin here is a way to permanently exclude pages globally across...
- Wordpress filter hook pre_comment_approved In this article, i will explain some problem that some...
- Disable Automatic Conversion Of URL To HTML Link In Wordpress Comment Disabling the automatic converting url or email addresses Wordpress sees...










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.