I want to ask that is there a way display all my custom taxonomies in a drop down menu with checkboxes so when the user check any taxonomy it will be slected and when the user click the submit button .the new post will be created with selected custom taxonomy. i know how to insert it in new post but i WANT TO KNOW ABOUT THE DROPDOWN WITH CHECKBOXES IN THE RED BOX
1 Answer
To list the options for a custom taxonomy you need to query the taxonomy terms. To do that you use get_terms()
http://codex.wordpress.org/Function_Reference/get_terms
// We are assuming color is the name of the taxonomy
$colors = get_terms( 'color', array(
'orderby' => 'name',
'hide_empty' => 0
));
// Now loop through the colors and spit out the checkbox
// with the name of the color as well as the value of the term_id
foreach($colors as $color){
....
On the server side for handling the submission (once you get the form correct) you can use wp_set_post_terms()
http://codex.wordpress.org/Function_Reference/wp_set_post_terms
-
-
1wp_insert_post returns the post_id which you pass in to wp_set_terms. You also need to pass in the taxonomy name (i.e. color) as well as the term_id's– RezenNov 29, 2012 at 22:41