Skip to content

Instantly share code, notes, and snippets.

@shaynesanderson-zz
Created May 14, 2013 01:22
Show Gist options
  • Save shaynesanderson-zz/5572914 to your computer and use it in GitHub Desktop.
Save shaynesanderson-zz/5572914 to your computer and use it in GitHub Desktop.
CPT dropdown meta in another CPT
<?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