- This topic has 5 replies, 3 voices, and was last updated 6 years, 10 months ago by
Steve.
Viewing 5 reply threads
-
AuthorPosts
-
-
April 8, 2015 at 3:08 pm #3589
GreggMemberHi Steve
I successfully created a taxonomy dropdown list for a CPT that’s employed on my widgets page as you can see in the attached.
It lists the available taxonomies, but is there a way to have an “All categories” option in the list?
Attachments:
You must be logged in to view attached files. -
April 8, 2015 at 3:50 pm #3591
jcristMemberYou could store the choices as a variable, add “All Categories” with a value of -1, then use ksort:
$choices = piklist( get_terms('category', array( 'hide_empty' => false )) ,array( 'term_id' ,'name' )); $choices[-1] = 'All Categories'; ksort($choices);Then references $choices as the…choices
-
April 8, 2015 at 10:23 pm #3593
GreggMemberCan you just clarify where the code you recommend should go. Here’s what I have:
piklist('field', array( 'type' => 'select' ,'field' => 'category' ,'label' => 'Categories' ,'conditions' => array( array( 'field' => 'gwfg_carousel_content_type' ,'value' => 'videos' ) ) ,'choices' => piklist( get_terms('gwfg_video_type', array( 'hide_empty' => false )) ,array( 'term_id' ,'name' ) ) ));Thanks.
-
April 9, 2015 at 9:00 am #3597
jcristMemberThis should do it:
$choices = piklist( get_terms('gwfg_video_type', array( 'hide_empty' => false )) ,array( 'term_id' ,'name' )); $choices[-1] = 'All Categories'; ksort($choices); piklist('field', array( 'type' => 'select' ,'field' => 'category' ,'label' => 'Categories' ,'conditions' => array( array( 'field' => 'gwfg_carousel_content_type' ,'value' => 'videos' ) ) ,'choices' => $choices )); -
April 9, 2015 at 9:49 am #3602
-
April 9, 2015 at 10:39 am #3606
-
-
AuthorPosts
Viewing 5 reply threads
- The topic ‘Taxonomy Dropdown List – All categories option’ is closed to new replies.