Support » Plugins » Hacks » term_exists parent zero

  • Hi,

    I have a term of category taxonomy called ‘Foo’ (id: 7) with parent ‘Bar’ (id: 5)
    If I check the existence of term Foo with parent 0 via:

    term_exists( 'Foo', 'category', 0 );

    it returns me the Bar children (with id: 7) instead of 0 / NULL as expected.
    That’s because in wp-includes/taxonomy around line 1591 ( 3.8.1 ) there is:

    if ( $parent > 0 ) {
            $where_fields[] = $parent;
            $else_where_fields[] = $parent;
            $where .= ' AND tt.parent = %d';
            $else_where .= ' AND tt.parent = %d';

    I don’t know if this is a bug or proper behaviour.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    The third term is not an immediate parent argument, it is more of a level from which to start searching. Since Foo is under top level, it is found. If you were to search under ID 8, a sibling of Bar, then nothing is found because the search only involved children of ID 8. Of course, searching under ID 5 would find Foo, as would searching from any parents above Bar.

Viewing 1 replies (of 1 total)
  • The topic ‘term_exists parent zero’ is closed to new replies.