Dev Corner

Software Developer’s Notepad

This tutorial shows how to retrieve tags associated with WordPress post. You can retrieve tags for the current post or any other post.

Solution

To retrieve a list of tags, you need the post ID:

$tags = get_the_tags($post_id);

The result in $tags is an array. For each tag assigned with the post, the $tags array contains an object that describes the tag. The tag object has following properties:

  • term_id
  • name
  • slug
  • term_group
  • term_taxonomy_id
  • taxonomy
  • description
  • parent
  • count
  • object_id

To retrieve a list of tags for the current post in WordPress Loop:

$tags = get_the_tags($post_id);

Add A Comment

You must be logged in to post a comment.