代碼有效!保存多個複選框元數據WordPress
我有兩種自定義帖子類型:Events
和Artists
。我正在使用WPAlchemy MetaBox PHP類,嘗試在Events
文章編輯器中創建一個帶有一系列動態創建的複選框的metabox(即,每個Artists
後都會有一個複選框),這將允許我選擇哪個Artists
出現在Event
。
任何幫助或洞察力非常感謝!謝謝!
此代碼工作正常顯示的複選框(從checkbox_meta.php):從functions.php的
<div class="my_meta_control">
<label>Group checkbox test #2</label><br/>
<?php
global $post;
$artists = get_posts('post_type=artists');
foreach($artists as $artist) :
setup_postdata($artist);
$slug = $artist->post_name;
?>
<?php $mb->the_field('cb_ex2', WPALCHEMY_FIELD_HINT_CHECKBOX_MULTI); ?>
<input type="checkbox" name="<?php $mb->the_name(); ?>" value="<?php echo $slug; ?>"<?php $mb->the_checkbox_state($slug); ?>/><?php echo $artist->post_title; ?><br/>
<?php endforeach; ?>
<input type="submit" class="button-primary" name="save" value="Save">
</div>
此代碼:
include_once 'assets/functions/MetaBox.php';
if (is_admin()) wp_enqueue_style('custom_meta_css', 'wp-content/themes/bam/assets/css/meta.css');
define('THEMEASSETS', STYLESHEETPATH . '/assets');
$custom_metabox = new WPAlchemy_MetaBox(array
(
'id' => '_custom_meta',
'title' => 'My Custom Meta',
'types' => array('sp_events'),
'template' => THEMEASSETS . '/functions/checkbox_meta.php'
));
非常感謝dimas!其實剛剛幾個小時前從朋友的推薦中檢查出您的網站 - 看起來很有希望! – 2011-05-03 23:39:47