get_tags()
Retrieve an array of tags objects. Tags can be retrieved by different criteria (see $args parameter).
Uses: get_terms()
Hooks from the function
Return
WP_Term[]|Int|WP_Error
. An array of WP_Term objects, or a count thereof.
Each object has these properties:
term_id
- ID of the tag;name
- name of the tag;slug
- slug;term_group
- group (not used);term_taxonomy_id
- ID of the taxonomy item (usually the same as term_id);taxonomy
- the name of the taxonomy;description
- description;parent
- ID of the parent's taxonomy (not used for tags);count
- posts count.
Usage template
$terms = get_tags( [ 'number' => 0, 'offset' => 0, 'orderby' => 'id', 'order' => 'ASC', 'hide_empty' => true, 'fields' => 'all', 'slug' => '', 'hierarchical' => true, 'name__like' => '', 'pad_counts' => false, 'get' => '', 'child_of' => 0, 'parent' => '', ] );
Usage
get_tags( $args );
- $args(string/array)
Tag arguments to use when retrieving tags.
See get_terms() for the list of arguments.
Default: ''
Examples
#1 Display the list of tags, in the form of links to each tag.
And set for the <a> tag a unique class and attribute title:
$tags = get_tags(); $html = '<div class="post_tags">'; foreach ( $tags as $tag ) { $tag_link = get_tag_link( $tag->term_id ); $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>"; $html .= "{$tag->name}</a>"; } $html .= '</div>'; echo $html;
Changelog
Since 2.3.0 | Introduced. |