WordPress.org

Ready to get started?Download WordPress

Forums

term_exists parent zero (2 posts)

  1. flentini
    Member
    Posted 4 months ago #

    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.

  2. bcworkz
    Member
    Posted 4 months ago #

    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.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.