A dropdown for taxonomy terms
-
Hi
i have read this document for get dropdown taxonomy term
https://github.com/CMB2/CMB2/wiki/Tips-&-Tricks#a-dropdown-for-taxonomy-terms-which-does-not-set-the-term-on-the-postBut this function get all taxonomy (parent children) all togheder
/**
Gets a number of terms and displays them as options
@param CMB2_Field $field
@return array An array of options that matches the CMB2 options array
*/
function cmb2_get_term_options( $field ) {
$args = $field->args( ‘get_terms_args’ );
$args = is_array( $args ) ? $args : array();$args = wp_parse_args( $args, array( ‘taxonomy’ => ‘category’ ) );
$taxonomy = $args[‘taxonomy’];
$terms = (array) cmb2_utils()->wp_at_least( ‘4.5.0’ )
? get_terms( $args )
: get_terms( $taxonomy, $args );// Initate an empty array
$term_options = array();
if ( ! empty( $terms ) ) {
foreach ( $terms as $term ) {
$term_options[ $term->term_id ] = $term->name;
}
}return $term_options;
}
How can fix this?
It’s good show the category 1 livel and after the category 2 livel
thx
- The topic ‘A dropdown for taxonomy terms’ is closed to new replies.