Codex tools: Log in
Contents |
Retrieves the terms associated with the given object(s), in the supplied taxonomies.
<?php wp_get_object_terms( $object_ids, $taxonomies, $args ) ?>
$args = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all');
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.
The first argument is called 'orderby' and has the default value of 'name'. Other supported values include 'count', 'slug', 'term_group', 'term_order', and 'term_id'.
The second argument is called 'order' and has the default value of 'ASC'. The only other value that will be acceptable is 'DESC'.
The final argument supported is called 'fields' and has the default value of 'all'. There are multiple other options that can be used instead. Supported values are as follows: 'all', 'ids', 'names', 'slugs', and finally 'all_with_object_id'.
The fields argument also decides what will be returned. If 'all' or 'all_with_object_id' is choosen or the default kept intact, then all matching terms objects will be returned. If 'ids', 'slugs' or 'names' is used, then an array of all matching term ids or term names will be returned respectively.
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>';
}
}
Since: 2.3.0
wp_get_object_terms() is located in wp-includes/taxonomy.php.