Title: has_term
Published: April 25, 2014
Last modified: May 20, 2026

---

# has_term( string|int|array $term = '', string $taxonomy = '', int|WP_Post|null $post = null ): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/has_term/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/has_term/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/has_term/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/has_term/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/has_term/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/has_term/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/has_term/?output_format=md#user-contributed-notes)

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

Checks if the current post has any of given terms.

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

The given terms are checked against the post’s terms’ term_ids, names and slugs.

Terms given as integers will only be checked against the post’s terms’ term_ids.

If no terms are given, determines if post has any terms.

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

 `$term`string|int|arrayoptional

The term name/term_id/slug, or an array of them to check for.

Default:`''`

`$taxonomy`stringoptional

Taxonomy name.

Default:`''`

`$post`int|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
|nulloptional

Post to check. Defaults to the current post.

Default:`null`

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

 bool True if the current post has any of the given terms (or any term, if no term
specified). False otherwise.

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

    ```php
    function has_term( $term = '', $taxonomy = '', $post = null ) {
    	$post = get_post( $post );

    	if ( ! $post ) {
    		return false;
    	}

    	$r = is_object_in_term( $post->ID, $taxonomy, $term );
    	if ( is_wp_error( $r ) ) {
    		return false;
    	}

    	return $r;
    }
    ```

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

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

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

Determines if the given object is associated with any of the given terms.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/has_term/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/has_term/?output_format=md#)

| Used by | Description | 
| [has_category()](https://developer.wordpress.org/reference/functions/has_category/)`wp-includes/category-template.php` |

Checks if the current post has any of given category.

  | 
| [has_tag()](https://developer.wordpress.org/reference/functions/has_tag/)`wp-includes/category-template.php` |

Checks if the current post has any of given tags.

  | 
| [redirect_canonical()](https://developer.wordpress.org/reference/functions/redirect_canonical/)`wp-includes/canonical.php` |

Redirects incoming links to the proper URL based on the site url.

  | 
| [has_post_format()](https://developer.wordpress.org/reference/functions/has_post_format/)`wp-includes/post-formats.php` |

Check if a post has any of the given formats, or any format.

  |

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

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

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/has_term/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 6 content](https://developer.wordpress.org/reference/functions/has_term/?output_format=md#comment-content-1892)
 2.    [Marc Heatley](https://profiles.wordpress.org/barkerbaggies/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/has_term/#comment-1892)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_term%2F%23comment-1892)
     Vote results for this note: 5[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_term%2F%23comment-1892)
 4.  If you’re checking for the presence of _any terms_ from a given taxonomy on a 
     post, you can pass in an empty string as the first parameter.
 5.  **Example**
 6.      ```php
         if( has_term('', 'genre') ){
         	// do something
         }
         ```
     
 7.  This is useful if you want to conditionally display some markup that applies only
     if terms have been added to a post.
 8.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_term%2F%3Freplytocom%3D1892%23feedback-editor-1892)
 9.   [Skip to note 7 content](https://developer.wordpress.org/reference/functions/has_term/?output_format=md#comment-content-580)
 10.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/has_term/#comment-580)
 11. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_term%2F%23comment-580)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_term%2F%23comment-580)
 12. **Example**
 13.     ```php
         if( has_term( 'jazz', 'genre' ) ) {
             // do something
         }
         ```
     
 14.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_term%2F%3Freplytocom%3D580%23feedback-editor-580)
 15.  [Skip to note 8 content](https://developer.wordpress.org/reference/functions/has_term/?output_format=md#comment-content-3750)
 16.   [Oscar Abad Folgueira](https://profiles.wordpress.org/oabadfol/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/has_term/#comment-3750)
 17. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_term%2F%23comment-3750)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_term%2F%23comment-3750)
 18. Example for check if a post of cpt have a specific term of a custom taxonomy.
     
     In this example we check if the post have a term ‘action’ and in this case asign
     one css class to a variable that we use later on html. CPT: “hook” Taxonomy: “
     hook-type” Taxonomy terms: “action” and “filter”. Note that in this example, this
     code is inside a cpt archive file “archive-hook.php”.
 19.     ```php
         $hook_css_class = '';
         if (has_term( 'action', 'hook-type' )) {
           $hook_css_class = "is-action-hook";
         } else {
           $hook_css_class = "is-filter-hook";
         };
         ```
     
 20.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_term%2F%3Freplytocom%3D3750%23feedback-editor-3750)
 21.  [Skip to note 9 content](https://developer.wordpress.org/reference/functions/has_term/?output_format=md#comment-content-6775)
 22.   [Ahir Hemant](https://profiles.wordpress.org/hemant-ahir/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/has_term/#comment-6775)
 23. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_term%2F%23comment-6775)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_term%2F%23comment-6775)
 24. The has_term function in WordPress is used to check if a post has a specific term(
     category, tag, or custom taxonomy term). Here’s an example:
 25.     ```php
         // Specify the term and taxonomy you want to check
         $term = 'wpdocs_term'; // Replace with the actual term slug or name
         $taxonomy = 'wpdocs_category'; // Replace with the actual taxonomy name
     
         // Specify the post ID you want to check
         $post_id = 1; // Replace with the actual post ID
     
         // Use has_term to check if the post has the specified term
         if ( has_term( $term, $taxonomy, $post_id ) ) {
             // The post has the specified term
             echo 'Post has the term ' . $term . ' in the ' . $taxonomy . ' taxonomy.';
         } else {
             // The post does not have the specified term
             echo 'Post does not have the term ' . $term . ' in the ' . $taxonomy . ' taxonomy.';
         }
         ```
     
 26.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_term%2F%3Freplytocom%3D6775%23feedback-editor-6775)
 27.  [Skip to note 10 content](https://developer.wordpress.org/reference/functions/has_term/?output_format=md#comment-content-6961)
 28.   [Hasan Fardous](https://profiles.wordpress.org/hasanfardous/)  [  2 years ago  ](https://developer.wordpress.org/reference/functions/has_term/#comment-6961)
 29. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_term%2F%23comment-6961)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_term%2F%23comment-6961)
 30.     ```php
         // Check for multiple categories at once by slugs
         has_term( array( 'album, genre' ), 'product_cat', 23 ) {
         	// do something
         }
     
         // Check for multiple categories at once by IDs
         has_term( array( '2', '5' ), 'product_cat', 23 ) {
         	// do something
         }
         ```
     
 31.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_term%2F%3Freplytocom%3D6961%23feedback-editor-6961)

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