Calendar Blackout Dates

I’ve been working on a friends site over at It’s nothing too crazy but has a form or a couple forms that can help them with setting up appointments, the general put your name, email and a few details about what your looking for.

The interesting bit came through with adding a calendar so you can pick what day you want the guys to come around. General jQuery datepicker showing inline which is all well and good except we needed the ability to block out the dates they can’t get around as they are already booked out.

This doesn’t seem to be something that is done very often in the way I’m looking for, possibly because it’s in wordpress or php or html or mysql or maybe I just don’t know the right tools for doing this, or I’m just searching the wrong key words. I’m running a backend page that looks pretty much the same as the front end but behind a login and only has the datepicker, this drops the date in a mysql database but bringing that array back into the front end page to block off the dates took a minute to figure out.

The database comes back in as an array and needs to be converted a single variable which can then be thrown into the script tag, this is the front end form.

get_col( "SELECT dates FROM jkb_blackout;" );
$string = '';

foreach ($array as $key => $value) {
$string .= ",$value";


Then the code for the functions.php file

// deals with variable set through form _POST
// Blackout
function prefix_admin_black() {

// deal with the upload
if ( ! function_exists( ‘wp_handle_upload’ ) ) {
require_once( ABSPATH . ‘wp-admin/includes/file.php’ );

// Extremley Important to set
global $wpdb;

// Whats inserted
$wpdb->insert( jkb_blackout ,
‘dates’ => $_POST[‘dates’]

// this give the unid in the next url
$id = $wpdb->insert_id;

// fail safe if above zero was inserted to database
if ($id>0) {
// Redirect
wp_redirect( home_url() . ‘/black’ );

} else {
// Redirect
wp_redirect( home_url() . ‘/sorry’ );


add_action( ‘admin_post_black’, ‘prefix_admin_black’ );
add_action( ‘admin_post_nopriv_black’, ‘prefix_admin_black’ );

I’m missing stuff on the fail states, errors security and things like that but for right now it’s working and you can check out some dates that have been blacked out on