how does get_term_by know which term to return when the same term appears twice in a hierarchical taxonomy?

This is from the codex.

<?php get_term_by( $field, $value, $taxonomy, $output, $filter ) ?>

Suppose I have a taxonomy system as follows;

Read More

taxonomy: “healthy foods”
and it’s a hierarchical taxonomy and your hierarchy goes exactly like this;

healthy foods
    fruits
        red ones
        green ones
    veggies
        red ones
        green ones

and you use the get_term_by function as follows;

get_term_by(“name”,”red ones”,”healthy foods”)

Do you get the veggies or the fruits?

Related posts

Leave a Reply

2 comments

  1. get_term_by() just returns the first matching term, ‘first’ meaning some internal order in MySQL.

    If having multiple terms with the same name matters in your case, don’t rely on get_term_by() alone.