在数组的数组中获取wordpress分类法


Get wordpress taxonomies in array of arrays

我想存储汽车模型。我为此创建了自定义分类法。

是这样的:

Audi
    A4
    A6
BMW
    X1
    X2
Mercedes-Benz
    C-Class
        180
        180d
    E-Class

例如,如果张贴关于奥迪A4 -我标记'奥迪'和'A4'。现在,在帖子中,我需要创建这辆车的名称- '奥迪A4'。我怎么能做到呢?

我尝试在wordpress loop中使用这样的东西:

$taxonomy = 'automobile';
$terms = wp_get_post_terms( get_the_ID(), $taxonomy, array( "fields" => "ids" ) );
$args = array( 'taxonomy' => $taxonomy, 'include' => $terms );
wp_list_categories( $args ); // Saved inheritance
$auto = get_categories($args); // Without inheritance

对于任何类似菜单的列表,使用Appearance->Menu。它将添加一堆类,如"current","current-ancestor"。您必须打开屏幕选项并选择分类法。