我有一个自定义字段来选择一个类别(自定义分类法),然后我将显示其所有子类别的列表。当我将自定义字段作为“term\\u id”返回时,这可以正常工作
然而我还想从这个选定的类别(父类别)中获取slug,这样我就可以链接到它的类别页面(我想我不能用ID链接到它)。所以我想也许我应该将自定义字段作为对象返回。这是它转储的内容:
stdClass Object ( [term_id] => 122 [name] => Quick Release Watch Bands [slug] => fits-all [term_group] => 0 [avhec_term_order] => 0 [term_taxonomy_id] => 122 [taxonomy] => product_cat [description] => Watch bands in many colors [parent] => 0 [count] => 293 [meta_id] => 1 [woocommerce_term_id] => 122 [meta_key] => order [meta_value] => 22 )
你知道我怎样才能从中取出ID(122)和slug(适合所有人)吗?这是到目前为止我的代码。自定义字段称为“selected\\u category”。
<?php $catid = get_sub_field(\'selected_category\');
$args = array(
\'taxonomy\' => \'product_cat\',
\'orderby\' => \'name\',
\'show_count\' => 0,
\'pad_counts\' => 0,
\'hierarchical\' => 1,
\'title_li\' => \'\',
\'depth\' => 1,
\'child_of\' => $catid
);
?>
<h4><a href="URL.COM/NEED-CATEGORY SLUG"><?php the_sub_field(\'title\'); ?></a></h4>
<ul class="subcats">
<?php wp_list_categories( $args ); ?>
</ul>
谁能帮帮我吗?非常感谢你!