Skip to content

Instantly share code, notes, and snippets.

@lgedeon
Created September 1, 2013 01:14
Show Gist options
  • Save lgedeon/6401708 to your computer and use it in GitHub Desktop.
Save lgedeon/6401708 to your computer and use it in GitHub Desktop.
clever way to find a term when you don't know what you have been given
} elseif ( isset ( $item->taxonomy ) && isset( $item->term ) ) {
if ( ( is_int( $item->term ) && $term = get_term_by( 'id', $item->term, $item->taxonomy ) )
|| ( $term = get_term_by( 'name', $item->term, $item->taxonomy ) )
|| ( $term = get_term_by( 'slug', $item->term, $item->taxonomy ) ) ) {
$item_array['menu-item-type'] = 'taxonomy';
$item_array['menu-item-object'] = $term->taxonomy;
$item_array['menu-item-object-id'] = $term->term_id;
$item_array['menu-item-title'] = ( $item_array['menu-item-title'] ) ?: $term->name;
} else {
continue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment