ABooooo
8/19/2014 - 8:01 PM

Add dropdown with posts to contact form

Add dropdown with posts to contact form

wpcf7_add_shortcode('postdropdown', 'createbox', true);
function createbox(){
global $post;
$args = array('numberposts' => 0, 'category' => 5 );
$myposts = get_posts( $args );
$output = "<select name='cursus' id='cursus' onchange='document.getElementById(\"cursus\").value=this.value;'><option></option>";
foreach ( $myposts as $post ) : setup_postdata($post);
	$title = get_the_title();
	$output .= "<option value='$title'> $title </option>";

	endforeach;
$output .= "</select>";
return $output;
}

// http://wordpress.org/support/topic/plugin-contact-form-7-add-drop-down-list-of-recent-posts