如何在WordPress中显示Post类型的子类别


How do i display the subcategory of Post type in WordPress?

我的类别结构如下类别结构:

Product 1
Product 2
    Product 2.1
    Product 2.2
Product 3
Product 4
    Product 4.1
    Product 4.2

如何获取所有类别&它在WordPress中的子类别。我的帖子类型名称是Product&分类名称为产品类别

这可能会对您有所帮助。。

<?php
//list terms in a given taxonomy using wp_list_categories  (also useful as a widget)
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$taxonomy = 'genre';
$title = '';
$args = array(
  'orderby' => $orderby,
  'show_count' => $show_count,
  'pad_counts' => $pad_counts,
  'hierarchical' => $hierarchical,
  'taxonomy' => $taxonomy,
  'depth'    => 2,
  'hide_empty' => 0,
  'title_li' => $title
);
?>
<ul>
<?php
wp_list_categories($args);
?>
</ul>