Retrieves the tags for a post.
Description
There is only one default for this function, called ‘fields’ and by default is set to ‘all’. There are other defaults that can be overridden in wp_get_object_terms() .
Parameters
$post_id
intoptional- The Post ID. Does not default to the ID of the global $post. Default 0.
$args
arrayoptional- Tag query parameters.
See WP_Term_Query::__construct() for supported arguments.Default:
array()
Source
function wp_get_post_tags( $post_id = 0, $args = array() ) {
return wp_get_post_terms( $post_id, 'post_tag', $args );
}
Changelog
Version | Description |
---|---|
2.3.0 | Introduced. |
For a post with tags tag2, tag5 and tag6, the code
displays
To get a list of only the tag IDs for a particular post:
and assuming the same dataset as the first example,
$tag_ids
would containDisplay a post specific list of tags,extending this from an example bhlarsen posted on get_tags() . There is probably a better way to do this.