Hey guys im trying to get the jQuery datepicker working for the admin section for a custom post type. Essentially I just want a date and then the ability to store that date in the DB then query the DB to pick things like the month. For now I just want the datepicker ui to start working and then I can work on adding the data to the DB. So i first added a jquery stylesheet and the jqueryui script using the admin_print_styles
and admin_enqueue_scripts
respectively.
function admin_styles() {
wp_register_style('jqueryuicss', '//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.min.css', array('jquery-ui-styles'), '1.12.1');
wp_enqueue_style('jqueryuicss');
}
add_action('admin_print_styles', 'admin_styles');
function admin_scripts() {
wp_register_script('jqueryui', '//code.jquery.com/ui/1.12.1/jquery-ui.min.js', array('jquery-ui'), '1.12.1', true);
wp_enqueue_script('jqueryui');
}
add_action('admin_enqueue_scripts', 'admin_scripts');
I then added the metabox to my custom post type.
function post_date_field() {
echo '<input type="text" id="jquery-datepicker" name="entry_post_date" value="' . get_post_meta( $post->ID, 'entry_post_date', true ) . '">';
}
function post_date_meta_box() {
add_meta_box('entry_post_date', 'Date', 'post_date_field', 'events', 'side', 'default');
}
add_action('add_meta_boxes', 'post_date_meta_box');
I have a library function that attempts to call the datepicker()
in a js library file:
function datepicker(){
jQuery('#jquery-datepicker').datepicker();
};
The date metabox appears in the edit post section but the jqueryui styles and script dont seem to run at all. Any suggestions on how to get this going? Just to get the scripts and styles registered and enqueued and get the date picker to pop up.