Created
August 19, 2014 20:01
-
-
Save ABooooo/b9ab151da9b7bb1e175a to your computer and use it in GitHub Desktop.
Add dropdown with posts to contact form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment