- This topic has 5 replies, 3 voices, and was last updated 5 years, 2 months ago by
Steve.
Viewing 5 reply threads
-
AuthorPosts
-
-
February 9, 2016 at 8:16 am #5882
helmiaditya14MemberI found this post and it’s exactly what I need from a custom taxonomy select. However, I’m not too savvy with the codes to dynamically generate it properly from a custom taxonomy. Anybody could help?
-
February 10, 2016 at 10:34 pm #5894
SteveKeymaster@helmiaditya14– Happy to help. I’m just not clear on the request. What do you need help with, creating the actual taxonomy?
-
February 11, 2016 at 5:02 am #5906
helmiaditya14MemberI was trying to replicate this code into the front end form.
piklist('field', array( 'type' => 'select' ,'field' => 'select_optgroup' ,'label' => __('Select with Option Groups', 'piklist-demo') ,'value' => 'third' ,'choices' => array( 'Group 1' => array( 'first' => __('First Choice', 'piklist-demo') ,'second' => __('Second Choice', 'piklist-demo') ,'third' => __('Third Choice', 'piklist-demo') ) ,'Group 2' => array( 'first' => __('First Choice', 'piklist-demo') ,'second' => __('Second Choice', 'piklist-demo') ,'third' => __('Third Choice', 'piklist-demo') ) ) ));But I can’t figure how to adjust the example to populate custom taxonomy. Any help appreciated!
-
February 15, 2016 at 9:32 am #5928
helmiaditya14MemberI didn’t know PHP that much to alter the code to generate custom taxonomy select dropdown with parent terms as optgroup. Anyone could help me?
Thanks!
-
November 15, 2016 at 10:17 am #7540
buishiMemberI know this is old, but this is how I did it:
$parents = get_terms(array( 'taxonomy' => 'case_category' ,'hide_empty' => false ,'parent' => 0 )); function choices($parent_cats){ $cats = []; foreach ($parent_cats as $parent) { $cats[$parent->name] = piklist( get_terms('case_category', array( 'hide_empty' => false ,'child_of' =>$parent->term_id )), array( 'term_id','name' )); } return $cats; } // var_dump(choices($parents)); piklist('field', array( 'type' => 'select', 'scope' => 'taxonomy', 'field' => 'case_category', 'label' => 'Category', 'attributes' => array( 'class' => 'form-control' ), 'choices' => choices($parents), 'required' => true, )); -
November 18, 2016 at 12:46 am #7560
-
-
AuthorPosts
Viewing 5 reply threads
- The topic ‘Custom Taxonomy with Optgroup’ is closed to new replies.