我需要计算Wordpress中的子类别数,但我无法处理它。有人知道怎么做吗?
答案 0 :(得分:3)
您可以计算所有类别并从中减去父类别以获取子类别。
$total_categories_count = wp_count_terms('category');
$parent_categories_count = count(get_categories('parent=0&hide_empty=0'));
$child_categories_count = $total_categories_count - $parent_categories_count;
希望这有帮助。
答案 1 :(得分:0)
mysql直接:
你应该尝试类似的东西:
SELECT categoria.id AS id_categoria, categoria.nome AS nome_categoria,
subcategoria.id AS id_subcategoria, subcategoria.nome AS nome_subcategoria
FROM categoria
INNER JOIN subcategoria
ON categoria.id = subcategoria.id_categoria
ORDER BY nome_categoria, nome_subcategoria
答案 2 :(得分:0)
$args = array('parent' => YOUR_PARENT_CATEGORY_ID_NUMBER);
$categories_cnt = count(get_categories( $args ));
echo 'There are '. $categories_cnt .' subcategories in this category';
那是你在找什么?