I'm trying to get a count of the categories that are subcategories of a category with the id $categoryId
.
In the documentation for the term query object, which is the primary argument to get_terms, the count
parameter is listed, with the description:
(bool) Whether to return a term count (true) or array of term objects (false). Will take precedence over $fields if true. Default false.
Based off of this, I think the following code should return an integer term count. However, it does not, it returns an array of term objects, the same as if I didn't include the count
argument. I've tried this with the values 1, "true", "True" and True as well.
get_terms(
array(
'parent' => $categoryId,
'taxonomy' => 'category',
'count' => true
)
);
After searching more, I found this code, which works:
wp_count_terms( 'category', array( 'parent' => $categoryId ) );
Why does the count
argument have no effect in this situation? Is this behavior consistent?