Last active
May 24, 2021 16:50
-
-
Save alkrauss48/10680354 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; | |
} |
Hello,
How would I make this select field required? The standard way does not work: [postdropdown* jobPosition post_type="job-opening"]
Unfortunately, possibly because of changes in CF7, this code no longer includes the output of the field in the mail
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to get category name on the option list category-title