Created
August 21, 2014 09:19
-
-
Save ABooooo/11a3bcca685607429a1c to your computer and use it in GitHub Desktop.
Add dropdown from post from two or more categories
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; | |
$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