Would like to know this as well.. Is there any code to use to get a custom function like the above?
Hi guys,
This is the code that makes it all work. Maybe not the best script? but it does really work. Simple add this function in 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);
$title = get_the_title();
$output .= "<option> $title </option>";
endforeach;
$output .= "</select>";
return $output;
}
With the shortcode in contactform 7 [postdropdown]. This will show all the posts titles in category 5.
Cheers!
To fully get it functioning, use this updated code:
Updated code:
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;
}
With the shortcode [postdropdown cursus] in the contactform to show posts from category 5. Put shortcode [cursus] in the mailtemplate.
cheers.
This is great! It doesn’t work when set with required (*). How can this be enabled?
hello ,
I want just to have the content of the post when I put the short code of contact form.
Can you help me to do that .?
Thanks a lot …
Guies please help me out
how can i achieve this from php dynamic values like
<input type=”text” value=”<?php the_title(); ?>” />
please help me out
Thanks for the code
Just want to share that I have modified the code so that it could be used within the blog pages without affecting the main loop
I also added in parameters like name and max width
wpcf7_add_shortcode('postdropdown', 'createbox', true);
function createbox($tag){
$name = $tag['name'];
$options = (array) $tag['options'];
$values = (array) $tag['values'];
foreach ($options as $option) {
if (preg_match('%^(\d*)[/x](\d*)$%i', $option, $matches)) {
$size_att = (int) $matches[1];
$maxlen_att = (int) $matches[2];
}
}
$args = array('category_name' => 'property-list' );
$output = "<select name='".$name."' id='".$name."' onchange='document.getElementById(\"" . $name ."\").value=this.value;' style='min-width:".$maxlen_att."px; max-width:".$maxlen_att."px; border:none; margin-top: 5px; margin-bottom:5px;'><option></option>";
$query2 = new WP_Query( $args );
// The 2nd Loop
while( $query2->have_posts()):
$query2->next_post();
$output .= "<option value='$title'>".get_the_title( $query2->post->ID )."</option>";
endwhile;
$output .= "</select>";
return $output;
}
So the shortcode will become [postdropdown post_selection /100] and mailtemplate can be [post_selection]
What if I want to shoow all the posts published by the user in a dropbox? I need this to let the contributors choose from this list the name of teh post they want the admin to be removed…