0

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?

1
  • Review Note: Close voted based on the answer given. Commented Oct 7, 2012 at 1:32

1 Answer 1

1

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.

1
  • 2
    How did you solve this?
    – Banago
    Commented Aug 29, 2013 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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