Home » Functions » get_term

Function Name: get_term

If you are building a WordPress site that involves categorizing content, then you will need to use the get_term function. This function allows you to retrieve a term object for a specified term, which can be a category, tag, or custom taxonomy.

The get_term function returns the term object, which includes properties such as the term ID, name, slug, and description. You can use this information to display the term on your site, or to perform further actions with the term, such as adding it to a post or filtering content by term.

Here’s an example of how to use the get_term function:

Suppose you have created a custom taxonomy called "book_genre" for your book review site, and you want to retrieve the term object for the "Mystery" genre. You can use the following code:

$term = get_term( 25, 'book_genre' );

In this code, "25" is the ID of the "Mystery" term, and "book_genre" is the name of the custom taxonomy. The get_term function will return the term object for this term, which you can then use to display information about the genre or to filter content by this genre.

Overall, the get_term function is an essential tool for any WordPress developer who needs to work with categories, tags, or custom taxonomies. By using this function, you can easily retrieve term objects and perform a wide range of actions with them.

Learn More on

Register an account to save your snippets or go Pro to get more features.