WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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',    

Here's my gallery_meta.php:

<div class="my_meta_control">
 <?php $metabox->the_field('attachedGallery'); ?>
    <label>Attached gallery </label>

        <select name="<?php $metabox->the_name(); ?>">
        <option value="0">select gallery</option>       
        //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(); ?>


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?

share|improve this question
Review Note: Close voted based on the answer given. – Brian Fegter Oct 7 '12 at 1:32

This was not WPAlchemy problem. It was a matter of running a custom query. Some vital information about current post, like ID of the post I was editing got lost.

share|improve this answer
How did you solve this? – Banago Aug 29 '13 at 8:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.