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. Tutorial: How to get image path on a post in Wordpress efficiently Wordpress did not provides a way to retrieve images on...
  2. 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...
  3. Sorting post according to post tag in Wordpress Sorting post according to its post tag in Wordpress is...
  4. Wordpress Plugin: Hungred Feature Post List Can't find any good feature plugin in the Wordpress market?...
  5. Tutorial: How to validate whether a user has logged into Wordpress A simple explanation on what Wordpress plugin developer will need...

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.