0

So here's my problem: I've created a Custom Post Type called "Projects". I've successfully added several metaboxes via WPAlchemy already. Those work fine. Where I'm having a problem is when I create a metabox with checkboxes for Related Projects, I can list out all the Project titles with checkboxes, but when I choose at least one and save the Custom post, it rewrites the Slug. I'm assuming it's because I'm calling <?php the_title(); ?>. Here is my code for the meta PHP file:

<div class="my_meta_control">

<p>Add or subtract Athena projects related to this project.</p>

<label>Available Projects</label><br/>

<?php 
    $items = new WP_Query(array(
            'post_type' => 'athena_project', 
            'posts_per_page' => 1000
    )); 
    while ( $items->have_posts() ) : $items->the_post();
?>
        <input type="checkbox" name="<?php $mb->the_name(); ?>" value="<?php echo the_title(); ?>"/><?php the_title(); ?><br />
    <?php endwhile; wp_reset_query(); ?>
    <br />
    <input type="submit" class="button-primary" name="save" value="Save" />
</div>

Does anyone have a good suggestion for getting around this problem?

1 Answer 1

0

So the solution after much cursing and pulling of hair was to ditch the WP_Query and go with get_posts instead, while referencing post_title like so:

<div class="my_meta_control">

<p>Add or subtract Athena projects related to this project.</p>

<label>Available Projects</label><br/>

<?php 
    $args = array('post_type' => 'athena_project', 'posts_per_page' => 1000);
    $items = get_posts($args);
    $mb->the_field('item', WPALCHEMY_FIELD_HINT_CHECKBOX_MULTI);

    foreach ($items as $item) { ?>
        <input type="checkbox" name="<?php $mb->the_name(); ?>" value="<?php echo $item->post_title; ?>" <?php $mb->the_checkbox_state($item->post_title); ?> /><?php echo $item->post_title; ?><br />
    <?php } ?>
    <br />
    <input type="submit" class="button-primary" name="save" value="Save" />
</div>

Now everything works beautifully.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.