I'm running a cusotm WP_Query
to get a handful of posts based on some parameters. Once I have the posts and I'm looping over them, I need to extract certain metadata elements, such as a list of tags for the post.
I see there's a function get_the_tags
for fetching an array of "tag objects", but I'm not seeing any references to where those are documented (i.e. what properties/methods do the tag objects have?)
I'm running a cusotm WP_Query
to get a handful of posts based on some parameters. Once I have the posts and I'm looping over them, I need to extract certain metadata elements, such as a list of tags for the post.
I see there's a function get_the_tags
for fetching an array of "tag objects", but I'm not seeing any references to where those are documented (i.e. what properties/methods do the tag objects have?)
1 Answer
Reset to default 0The tag objects returned by get_the_tags()
use WP_term
class. You can see this by inspecting the function's source. The class is mentioned on the last line of the comment.
function get_the_tags( $id = 0 ) {
/**
* Filters the array of tags for the given post.
*
* @since 2.3.0
*
* @see get_the_terms()
*
* @param WP_Term[] $terms An array of tags for the given post.
*/
return apply_filters( 'get_the_tags', get_the_terms( $id, 'post_tag' ) );
}