Cualquier esperanza de que este menú desplegable de taxonomía funcione con jerárquicos.

¡Agregué 'hierarchical' => 1 pero parece que no funciona para mí!

<?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
Adham Mohamed 15 oct. 2018 a las 22:59

2 respuestas

La mejor respuesta

Utilizar la función 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'] ); ?>
0
Parsa 15 oct. 2018 a las 20:58
  <?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',

); ?>

0
Raihan Islam 15 oct. 2018 a las 21:19