get_tags() WordPress Function

The get_tags() function in WordPress is used to return an array of all tags associated with a given post. This function can be used in conjunction with the tag_ Clouds() function to create a list of all tags associated with a given post, or it can be used alone to retrieve an array of all tags for a given post.

get_tags( string|array $args = '' ) #

Retrieves all post tags.


Parameters

$args

(string|array)(Optional)Arguments to retrieve tags. See get_terms() for additional options.

  • 'taxonomy'
    (string) Taxonomy to retrieve terms for. Default 'post_tag'.

Default value: ''


Top ↑

Return

(WP_Term[]|int|WP_Error) Array of 'post_tag' term objects, a count thereof, or WP_Error if any of the taxonomies do not exist.


Top ↑

Source

File: wp-includes/category.php

function get_tags( $args = '' ) {
	$defaults = array( 'taxonomy' => 'post_tag' );
	$args     = wp_parse_args( $args, $defaults );

	$tags = get_terms( $args );

	if ( empty( $tags ) ) {
		$tags = array();
	} else {
		/**
		 * Filters the array of term objects returned for the 'post_tag' taxonomy.
		 *
		 * @since 2.3.0
		 *
		 * @param WP_Term[]|int|WP_Error $tags Array of 'post_tag' term objects, a count thereof,
		 *                                     or WP_Error if any of the taxonomies do not exist.
		 * @param array                  $args An array of arguments. @see get_terms()
		 */
		$tags = apply_filters( 'get_tags', $tags, $args );
	}

	return $tags;
}


Top ↑

Changelog

Changelog
VersionDescription
2.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.