Ready to get started?Download WordPress


Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp get object terms


Retrieves the terms associated with the given object(s), in the supplied taxonomies.


<?php wp_get_object_terms$object_ids$taxonomies$args ?>


(string|array) (required) The id's of objects to retrieve terms from.
Default: None
(string|array) (required) The taxonomies to retrieve terms from. For example: 'category', 'post_tag', 'taxonomy slug'
Default: None
(array|string) (optional) Change what is returned
Default: array

Default Arguments

$args = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all');

Argument Options

The following information has to do the $args parameter and for what can be contained in the string or array of that parameter, if it exists.

  • ASC - Default
  • DESC
  • name - Default
  • count
  • slug
  • term_group
  • term_order
  • term_id
  • none
  • all - Default : all matching terms objects will be returned.
  • ids : terms ids will be returned
  • names : terms names will be returned
  • slugs : terms slugs will be returned
  • all_with_object_id : all matching terms objects will be returned.
  • tt_ids : terms taxonomies ids will be returned

NOTE: Arguments are passed in the format used by wp_parse_args(). e.g.

Return Values

Array of requested term objects or empty array if no terms found. WP_Error if $taxonomy does not exist. See is_wp_error() for more information.


Return a list of all 'product' taxonomy terms which are applied to $post:

$product_terms = wp_get_object_terms( $post->ID,  'product' );
if ( ! empty( $product_terms ) ) {
	if ( ! is_wp_error( $product_terms ) ) {
		echo '<ul>';
			foreach( $product_terms as $term ) {
				echo '<li><a href="' . get_term_link( $term->slug, 'product' ) . '">' . $term->name . '</a></li>'; 
		echo '</ul>';


Change Log

Since: 2.3.0

Source File

wp_get_object_terms() is located in wp-includes/taxonomy.php.


See also index of Function Reference and index of Template Tags.