} // If only one match was found, it's the one we want.
} elseif ( 1 ===
count( $terms ) ) { $_term =
reset( $terms );
// Otherwise, the term must be shared between taxonomies.
} else { // If the term is shared only with invalid taxonomies, return the one valid term.
foreach ( $terms as $t ) { if ( !
taxonomy_exists( $t->taxonomy
) ) { continue;
} // Only hit if we've already identified a term in a valid taxonomy.
if ( $_term ) { return new WP_Error( 'ambiguous_term_id',
__( 'Term ID is shared between multiple taxonomies'
),
$term_id );
} $_term =
$t;
} }