I’m using WP Alchemy to create a meta box in a post that allows the user to select from a list of categories. However I can’t seem to echo the value, once saved. (Dima, hoping you can help me on this!) What am I doing wrong? Thanks in advance!!!
From functions.php:
$catPos_metabox = new WPAlchemy_MetaBox(array
(
'id' => '_catPosition',
'title' => 'Category Position',
'template' => STYLESHEETPATH . '/assets/functions/select_meta.php',
'include_post_id' => 33
));
From select_meta.php:
<div class="my_meta_control">
<label class="space">Space One</label><br/>
<?php $mb->the_field('space1'); ?>
<select name="<?php $mb->the_name(); ?>">
<?php
$cats = get_categories();
foreach($cats as $cat) {
$catID = $cat->term_id;
$catName = $cat->name;
?>
<option value="<?php echo $catID; ?>" <?php $mb->the_select_state($catID); ?>><?php echo $catName; ?></option>
<?php } ?>
</select> <!-- space one -->
<div class="clear"></div>
</div>
From the template, homepage.php:
<?php
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
global $catPos_metabox;
$catPos_metabox->the_meta();
echo $catPos_metabox->the_value('spaceOne');
endwhile; endif;
?>
HTML Output for the metabox on post editor:
<div id="_catPosition_metabox" class="postbox " >
<div class="handlediv" title="Click to toggle">
<br />
</div>
<h3 class='hndle'><span>Category Position</span></h3>
<div class="inside">
<div class="my_meta_control">
<label class="space">Space One</label><br/>
<select name="_catPosition[space1]">
<option value="5" >Arts & Culture</option>
<option value="3" >Fashion</option>
<option value="4" selected="selected">Music</option>
<option value="1" >Uncategorized</option>
</select> <!-- space one -->
<div class="clear"></div>
</div>
<input type="hidden" name="_catPosition_nonce" value="f8c2617abe" />
</div>
Sometimes you will need to do the following: