2

Code works!

I have two custom post types: Events and Artists. I'm using WPAlchemy MetaBox PHP class , trying to create a metabox with a series of dynamically created checkboxes (i.e. there will be a checkbox for each Artists post) in the Events post editor that will allow me to select which Artists are appearing at an Event.

Any help or insight much appreciated! Thanks!

This code works fine to display the checkboxes (from 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>

This code from 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 Answers 2

1

I've developed a helper class which might help you with creating wordpress meta boxes.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks alot dimas! Actually just checked out your site a few hours ago from a recommendation from a friend-- looks very promising!
0

I think this line is the problem

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

Try to change it to

$data = stripslashes_deep($_POST);

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.