Notes

Since the term can be an object, integer, or string, make sure that any numbers you pass in are explicitly converted to an integer (example: (int) $term_id). Otherwise the function will assume that $term is a slug instead of a term ID.

Because of the above, $term->term_id doesn't work for the $term parameter prior to 3.8.0. See this trac ticket for more info.

PHP may halt if you attempt to print an error result ("Catchable fatal error: Object of class WP_Error could not be converted to string"). You should always use is_wp_error() to check the result of this function, in case the term does not exist.

Change Log

3.1.0: $taxonomy is optional when passing a term object. It is still required if $term is passed as a string. See ticket #13081.