我使用这段代码来获取自定义分类法的term\\u id。下拉列表确实列出了分类法类型的术语。当我打印$terms变量时,我会在前端看到我正在编辑的文章的术语ID。为什么没有将术语ID设置为所选选项?
$terms = get_the_terms( $current_post, \'Type\' );
print_r($terms);
wp_dropdown_categories( \'taxonomy=Type&hierarchical=1&hide_empty=0&id=cat&show_count=0&selected=\' . $terms[0]->term_id );
这是数组的输出
Array ( [25] => stdClass Object ( [term_id] => 25 [name] => Sativa [slug] => sativa [term_group] => 0 [term_icon] => http://pothwy.com/wp-content/themes/GeoPlaces/images/default.png [term_price] => 0 [term_taxonomy_id] => 53 [taxonomy] => Type [description] => [parent] => 0 [count] => 4 [object_id] => 563 ) )
HTML输出
<select name="cat" id="cat" class="postform">
<option class="level-0" value="25">Sativa</option>
<option class="level-0" value="52">Indica</option>
</select>