Title: get_tag
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_tag( int|WP_Term|object $tag, string $output = OBJECT, string $filter ): 󠀁[WP_Term](https://developer.wordpress.org/reference/classes/wp_term/)󠁿|array|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿|null

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_tag/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_tag/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_tag/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_tag/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_tag/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_tag/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_tag/?output_format=md#wp--skip-link--target)

Retrieves a post tag by tag ID or tag object.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_tag/?output_format=md#description)󠁿

If you pass the $tag parameter an object, which is assumed to be the tag row object
retrieved from the database, it will cache the tag data.

If you pass $tag an integer of the tag ID, then that tag will be retrieved from 
the database, if it isn’t already cached, and passed back.

If you look at [get_term()](https://developer.wordpress.org/reference/functions/get_term/),
both types will be passed through several filters and finally sanitized based on
the $filter parameter value.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_tag/?output_format=md#parameters)󠁿

 `$tag`int|[WP_Term](https://developer.wordpress.org/reference/classes/wp_term/)
|objectrequired

A tag ID or object.

`$output`stringoptional

The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
a [WP_Term](https://developer.wordpress.org/reference/classes/wp_term/) object, 
an associative array, or a numeric array, respectively.

Default:`OBJECT`

`$filter`stringoptional

How to sanitize tag fields. Default `'raw'`.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_tag/?output_format=md#return)󠁿

 [WP_Term](https://developer.wordpress.org/reference/classes/wp_term/)|array|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
|null Tag data in type defined by $output parameter.
 [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
if $tag is empty, null if it does not exist.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_tag/?output_format=md#source)󠁿

    ```php
    function get_tag( $tag, $output = OBJECT, $filter = 'raw' ) {
    	return get_term( $tag, 'post_tag', $output, $filter );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/category.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/category.php#L341)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/category.php#L341-L343)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_tag/?output_format=md#related)󠁿

| Uses | Description | 
| [get_term()](https://developer.wordpress.org/reference/functions/get_term/)`wp-includes/taxonomy.php` |

Gets all term data from database by term ID.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_tag/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.3.0](https://developer.wordpress.org/reference/since/2.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_tag%2F)
before being able to contribute a note or feedback.