[Plugin: Contact Form 7]Create a selectbox from database?
-
Hi guys,
I am trying to create a custom dropdown (select) box in my Contactform with values (post titles from category id 5) from the database, called by a custom shortcode.To do so i put the following function/code in my functions.php
wpcf7_add_shortcode('postdropdown', 'createbox'); function createbox(){ global $post; $args = array( 'category' => 5 ); $myposts = get_posts( $args ); $output = '<select name="lstdate" id="fleet" onchange="document.getElementById(\'fleet\').value=this.value;"><option></option>'; foreach ( $myposts as $post ) : setup_postdata($post); $output .= "<option> the_title(); </option>"; endforeach; $output .= "</select>"; return $output; }
When i add the shortcode [postdropdown] in my contactform a dropdown menu does show up, but the value is “the_title();” instead of the concerning post title from category_id 5.
What am i doing wrong? Can anyone help me?
thanks
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘[Plugin: Contact Form 7]Create a selectbox from database?’ is closed to new replies.