Here is what I'm basically trying to accomplish:
- I have a custom post type called 'quotes'
- I have a number of wordpress pages
What I am trying to do is this: each time when I create a new "QUOTES" post, I want to be able to choose on which page this quotes post is supposed to go. I've decided to do this by creating a new metabox on the "quotes" post page and listing in that metabox all the pages, with a checkbox in front of them:
All fine and well, but now I don't know how to save these checkboxes.
Here is the function I use to print the content of the metabox:
function myplugin_inner_custom_box( $post ) {
$custom = get_post_custom($post->ID);
$checkfield = $custom["checkfield"][0];
// Nonce to verify intention later
wp_nonce_field( 'save_quote_meta', 'custom_nonce' );
$pages = get_pages();
foreach ( $pages as $page ) { ?>
<input type="checkbox" name="checkfield_<?php echo $page->ID; ?>" value="yes" <?php if ($checkfield == 'yes') { ?> checked <?php } ?> /> <?php echo $page->post_title; ?> <br>
<?php
}
}
And here is the function I use to save them:
//save the meta box action
add_action( 'save_post', 'myplugin_meta_save' );
//save the meta box
function myplugin_meta_save()
{
global $post;
update_post_meta($post->ID, 'checkfield', $_POST['checkfield'] );
}
Obviously this doesn't work - I am not sure how to save all those checkfields values.