Skip to content

Instantly share code, notes, and snippets.

@zachlysobey
Created June 5, 2012 13:24
Show Gist options
  • Select an option

  • Save zachlysobey/2874957 to your computer and use it in GitHub Desktop.

Select an option

Save zachlysobey/2874957 to your computer and use it in GitHub Desktop.
wpalchemy metabox with "loop"
<div class="my_meta_control">
<?php $mb->the_field('assoc_proj'); ?>
<p style="margin:2px 0;">
<span style="float:left">What Project is this case study associated with?</span><br />
<select name="<?php $mb->the_name(); ?>">
<?php
$selected = ' selected="selected"';
global $post;
$args = array( 'post_type' => 'projects', 'posts_per_page' => 200 );
$custom_posts = get_posts($args);
foreach($custom_posts as $post) : setup_postdata($post);
echo '<option value="' . get_the_id() . '"';
if ($mb->get_the_value() == get_the_id() ) echo $selected;
echo '>' . get_the_title() . '</option>' . "\n";
endforeach;
?>
</select>
</p>
<p style="margin-bottom:15px; padding-top:5px;">
<input type="submit" class="button" name="save" value="Save" />
</p>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment