Using output of get_terms in form
-
I’m currently making a plugin for users to submit Lyrics to my site.
I am stuck with one part of creating the form for users to submit their lyrics. I had previously decided to use a selection of categories I had added to the plugin, but now I’d like to use a custom taxonomy (which is registered but not registered in this same plugin). Working code for quote categories was this:function suq_get_create_quote_form($suq_quote_author = '', $suq_quote_text = '', $suq_quote_category = 0){ $out .= '<form id="create_quote_form" method="post" action="">'; $out .= wp_nonce_field('suq_form_create_quote', 'suq_form_create_quote_submitted'); $out .= '<label for="suq_quote_author">Who said it?</label><br/>'; $out .= '<input type="text" id="suq_quote_author" name="suq_quote_author" value="' . $suq_quote_author . '"/><br/>'; $out .= '<label for="suq_quote_category">Category</label><br/>'; $out .= suq_get_quote_categories_dropdown('quote_category', $suq_quote_category) . '<br/>'; $out .= '<label for="suq_quote_text">Quote</label><br/>'; $out .= '<textarea id="suq_quote_text" name="suq_quote_text" />' . $suq_quote_text . '</textarea><br/><br/>'; $out .= '<input type="submit" id="suq_submit" name="suq_submit" value="Submit Quote For Publication">'; $out .= '</form>'; return $out; } function suq_get_quote_categories_dropdown($taxonomy, $selected){ return wp_dropdown_categories(array('taxonomy' => $taxonomy, 'name' => 'suq_quote_category', 'selected' => $selected, 'hide_empty' => 0, 'echo' => 0)); }
Since I’d like to use my taxonomy
hhie_artists
I am trying to modify the second function above. Here is where I am so far:function suq_get_create_quote_form($suq_quote_author = '', $suq_quote_text = '', $suq_quote_category = 0){ $out .= '<form id="create_quote_form" method="post" action="">'; $out .= wp_nonce_field('suq_form_create_quote', 'suq_form_create_quote_submitted'); $out .= '<label for="suq_quote_author">Who said it?</label><br/>'; $out .= '<input type="text" id="suq_quote_author" name="suq_quote_author" value="' . $suq_quote_author . '"/><br/>'; $out .= '<label for="suq_quote_category">Category</label><br/>'; $out .= get_terms_dropdown($taxonomy, $suq_quote_category) . '<br/>'; $out .= '<label for="suq_quote_text">Quote</label><br/>'; $out .= '<textarea id="suq_quote_text" name="suq_quote_text" />' . $suq_quote_text . '</textarea><br/><br/>'; $out .= '<input type="submit" id="suq_submit" name="suq_submit" value="Submit Quote For Publication">'; $out .= '</form>'; return $out; } function get_terms_dropdown($taxonomy, $args){ $myterms = get_terms($taxonomy, $args); $output ="<select>"; foreach($myterms as $term){ $root_url = get_bloginfo('url'); $term_taxonomy=$term->taxonomy; $term_slug=$term->slug; $term_name =$term->name; } $output ="</select>"; return $output; $taxonomy = array('hhie_artists'); $args = array('orderby'=>'name','hide_empty'=>true); }
But no dropdown is returned under the Category label on output.
get_terms
code was taken from this thread.
Can anyone help?
- The topic ‘Using output of get_terms in form’ is closed to new replies.