Wordpress - taxonomy dropdown is not working with hierarchical

廉价感情. 提交于 2019-12-25 04:12:33

问题


Any hope to make this Taxonomy dropdown to work with hierarchical.

I added 'hierarchical' => 1 but it seems doesn't work for me!

<?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;
?>

回答1:


use wp_dropdown_categories function

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'] ); ?>



回答2:


  <?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',

); ?>



来源:https://stackoverflow.com/questions/52823925/wordpress-taxonomy-dropdown-is-not-working-with-hierarchical

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!