I'm building a query to get the child's child categories. For example : I have a parent category named 'animal' and others like 'food' and 'sport'. I want to get animal's sub categories.
I do :
$parent_cat = get_cat_ID( $cat_name );
$args = array(
'type' => 'post',
'parent' => $parent_cat,
'order' => 'DESC'
);
$categories = (array) get_categories( $args );
And no problem, with a foreach I get my animal's sub categories.
In my sub categories, I also have categories (this is a 3 levels hierarchy).
I do the same :
$child_cat = get_cat_ID( $sub_cat_name );
$args = array(
'type' => 'post',
'parent' => $child_cat,
'order' => 'DESC'
);
$sub_categories = (array) get_categories( $args );
And... it returns the others parents categories 'food' an 'sport'.
Why that ? Where am I wrong ?
$child_cat
is not what you think it is. make sure$sub_cat_name
contains the correct name and that$child_cat
is not 0.