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 ?

Read more here: Query child’s child categories


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , ,

Wordpress related questions and answers: