任何希望使此分类法下拉列表与分层一起工作的人。
我添加了'hierarchical' => 1
,但似乎对我不起作用!
<?php
if( $terms = get_terms([ 'taxonomy' => 'category', 'hierarchical' => 1, 'hide_empty' => false, 'child_of' => 233 ]) ) :
echo '<select name="categoryfilter4"><option>Downloads...</option>';
foreach ( $terms as $term ) :
echo '<option value="' . $term->term_id . '">' . $term->name . '</option>'; // ID of the category as the value of an option
endforeach;
echo '</select>';
endif;
?>
答案 0 :(得分:0)
使用wp_dropdown_categories函数
https://codex.wordpress.org/Function_Reference/wp_dropdown_categories
<?php wp_dropdown_categories( ['name'=>'categoryfilter4', 'show_option_none' => 'Downloads...','hierarchical' => 1, 'hide_empty' => false, 'child_of' => 233, 'order_by' => 'parent'] ); ?>
答案 1 :(得分:0)
<?php wp_dropdown_categories( $args ); ?>
<?php $args = array(
'show_option_all' => '',
'show_option_none' => '',
'option_none_value' => '-1',
'orderby' => 'ID',
'order' => 'ASC',
'show_count' => 0,
'hide_empty' => 1,
'child_of' => 0,
'exclude' => '',
'include' => '',
'echo' => 1,
'selected' => 0,
'hierarchical' => 0,
'name' => 'cat',
'id' => '',
'class' => 'postform',
'depth' => 0,
'tab_index' => 0,
'taxonomy' => 'category',
'hide_if_empty' => false,
'value_field' => 'term_id',
); ?>