I am looking to create a custom metabox with check-boxes that will serve to display item availability. I have included two sample images of what I am wishing to accomplish. Any Help would be much appreciated.

Moreover, I am really just trying to figure out where to start on this problem. For more information, I will be creating a custom post type that will be specific to Menu Items. This is for a local cupcake bakery.





If you have created you custom post type you can add the metabox like this:

add_action( 'add_meta_boxes', 'add_dates' );

function add_dates() {
    add_meta_box('date_select', 'Dates', 'date_select', 'customposttype', 'side', 'default');

function date_select() {
    global $post;
    echo '<input type="hidden" name="date_select_meta_noncename" id="date_select_meta_noncename" value="' .
    wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
    $gender = get_post_meta($post->ID, '_date', true);

    // Insert checkboxes HTML

Then you need to save the custom meta data.

function save_dates($post_id, $post) {

    if ( !wp_verify_nonce( $_POST['date_select_meta_noncename'], plugin_basename(__FILE__) )) {
        return $post->ID;

    if ( !current_user_can( 'edit_post', $post->ID ))
        return $post->ID;

    $date_meta['_date'] = $_POST['_date'];

    foreach ($date_meta as $key => $value) { 

        if( $post->post_type == 'revision' ) return; 
        $value = implode(',', (array)$value);         
        if(get_post_meta($post->ID, $key, FALSE)) {
            update_post_meta($post->ID, $key, $value);
        } else {
            add_post_meta($post->ID, $key, $value);
        if(!$value) delete_post_meta($post->ID, $key); 

add_action('save_post', 'save_dates', 1, 2);

Of course you will need to set it up for you custom post type.

(Caveat: not tested)

  • If there is anything else I can do let me know.
    – Ryan
    Mar 14 '12 at 12:28

This is a great tutorial about adding custom meta boxes - http://www.netmagazine.com/tutorials/user-friendly-custom-fields-meta-boxes-wordpress

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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