我正在使用WPalchemy metabox类向页面编辑器添加一个额外的元字段,这将允许我将库附加到页面。我使用该类:
$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
));
这是我的gallery\\u 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>
对于帖子/页面和事件,输入字段显示在WP admin中。当我保存值时,它似乎无法保存。我检查了mysql数据库,对于我正在测试的这个特定页面,有一行带有:meta\\u key
_gallery_meta
meta\\u值
a:1:{s:16:"attached-gallery";s:3:"109";}
我无法检索$gallery\\u元框的值,也无法使select元素将选项标记为选中。有人能帮忙吗?