0

I'm looping though child categories of a given parent, but what I've noticed is that it doesn't get echoed if the child category itself doesn't have any posts in relation to it. How can I echo children even though they don't have any posts?

    $children = get_categories(
        array( 'parent' => 923)
    );

    foreach ($children as $child) {  
        echo "<h6>Child: " . $child->name . "</h6>"; 
    }

1 Answer 1

1

By default, get_categories() won't return terms that have no posts (the hide_empty parameter is true).

This should do it:

$children = get_categories(
    array(
        'parent'     => 923,
        'hide_empty' => false,
    )
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.