保存多个复选框元数据WordPress

时间:2011-05-01 19:09:14

标签: php wordpress custom-fields custom-field-type

代码有效!

我有两种自定义帖子类型:EventsArtists。我正在使用WPAlchemy MetaBox PHP类,试图在Artists帖子编辑器中创建一个带有一系列动态创建的复选框的元数据(即每个Events帖子都会有一个复选框)选择Artists出现的Event

非常感谢任何帮助或见解!谢谢!

此代码可以正常显示复选框(来自checkbox_meta.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>

来自functions.php的代码:

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'
));

2 个答案:

答案 0 :(得分:1)

我开发了一个帮助程序类,它可以帮助您creating wordpress meta boxes

答案 1 :(得分:0)

我认为这一行是问题

$data = stripslashes_deep($_POST['artist']);

尝试将其更改为

$data = stripslashes_deep($_POST);