Created
May 14, 2013 01:22
-
-
Save shaynesanderson-zz/5572914 to your computer and use it in GitHub Desktop.
CPT dropdown meta in another CPT
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
<?php | |
add_action( 'cmb_render_location_list', 'dss_cmb_render_location_list', 10, 2 ); | |
function dss_cmb_render_location_list( $field, $meta ) { | |
global $post; | |
$tmp_post = $post; | |
// set the args | |
$args = array ( | |
'post_type' => 'locations', | |
'posts_per_page' => -1, | |
'orderby' => 'title', | |
'order' => 'ASC' ); | |
// call the query | |
$myposts = get_posts( $args ); | |
echo '<select name="', $field['id'], '" id="', $field['id'], '">'; | |
echo '<option value="">Please Select</option>'; | |
foreach( $myposts as $post ) : setup_postdata($post); | |
echo '<option value="', $post->ID, '"', $meta == $post->ID ? ' selected="selected"' : '', '>', $post->post_title, '</option>'; | |
endforeach; | |
echo '</select>'; | |
$post = $tmp_post; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment