Skip to content

Instantly share code, notes, and snippets.

@ABooooo
Created August 21, 2014 09:19
Show Gist options
  • Save ABooooo/11a3bcca685607429a1c to your computer and use it in GitHub Desktop.
Save ABooooo/11a3bcca685607429a1c to your computer and use it in GitHub Desktop.
Add dropdown from post from two or more categories
wpcf7_add_shortcode('postdropdown', 'createbox', true);
function createbox(){
global $post;
$args1 = array('numberposts' => 0, 'category' => 14 );
$myposts1 = get_posts( $args1 );
$args2 = array('numberposts' => 0, 'category' => 19 );
$myposts2 = get_posts( $args2 );
$myposts = array_merge($myposts1, $myposts2);
$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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment