I am using WPalchemy metabox class to add a extra meta field to the pages editor which will allow me to attach galleries to pages. I use the class:
$gallery_metabox = new WPAlchemy_MetaBox(array(
'id' => '_gallery_meta',
'title' => 'Gallery',
'template' => STYLESHEETPATH . '/inc/custom/gallery_meta.php',
'types' => array('post', 'page', 'events'),
'priority' => 'high',
'lock' => WPALCHEMY_LOCK_AFTER_POST_TITLE
));
Here's my gallery_meta.php:
<div class="my_meta_control">
<?php $metabox->the_field('attachedGallery'); ?>
<label>Attached gallery </label>
<p>
<select name="<?php $metabox->the_name(); ?>">
<option value="0">select gallery</option>
<?php
//global $post;
$selected = 'selected="selected"';
$args = array( 'post_type' => 'galleries', 'posts_per_page' => 999, 'orderby' => 'title', 'order' => 'ASC' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();?>
<option value="<?php the_ID(); ?>" <?php echo $mb->is_value(get_the_ID())? $selected :''; ?>><?php the_title(); ?></option>
<?php endwhile; wp_reset_query(); ?>
</select>
</p>
</div>
The input field appears in the WP admin for posts/ pages and events. When I save the value it seems it doesn't save. I checked the mysql db and for this particular page I am testing there is a row with:
meta_key _gallery_meta
meta_value a:1:{s:16:"attached-gallery";s:3:"109";}
I can't retrieve the value of the $gallery_metabox or make the select element mark the option as selected though. Can anyone help?