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 :)

 

Like this post? Share it!

http://hungred.com/wp-content/plugins/sociofluid/images/digg_48.png http://hungred.com/wp-content/plugins/sociofluid/images/reddit_48.png http://hungred.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png http://hungred.com/wp-content/plugins/sociofluid/images/delicious_48.png http://hungred.com/wp-content/plugins/sociofluid/images/furl_48.png http://hungred.com/wp-content/plugins/sociofluid/images/technorati_48.png http://hungred.com/wp-content/plugins/sociofluid/images/google_48.png http://hungred.com/wp-content/plugins/sociofluid/images/myspace_48.png http://hungred.com/wp-content/plugins/sociofluid/images/facebook_48.png http://hungred.com/wp-content/plugins/sociofluid/images/twitter_48.png

Related posts:

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

This entry was posted on Saturday, November 28th at 12:53 PM and is filed under How-to, Others. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

5 User Commented

  1. 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. no problem, glad it helps :)

  3. This only works inside the loop?

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

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

Comments are automatic closed after certain period. Please send the author an email instead.