Forked from alkrauss48/custom_post_type_cf7_dropdown.php
Created
May 24, 2016 10:52
-
-
Save govindak/af54bf3aa7d00f3d037b3dc1b2d94bc0 to your computer and use it in GitHub Desktop.
Adding a custom Wordpress shortcode for building a dynamic dropdown of post type titles with Contact Form 7
This file contains 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; | |
extract( shortcode_atts( array( 'post_type' => 'some_post_type',), $atts ) ); | |
$args = array('post_type' => $post_type ); | |
$myposts = get_posts( $args ); | |
$output = "<select name='postType' id='postType' onchange='document.getElementById(\"postType\").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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment