adding jquery to custom meta box
-
Hello there fellow WordPress Gurus.
After hours of trying to figure this out I figured I would ask the community in hope for getting a quick response.
My problem is fairly simple. All I am trying to do is add a custom meta box allowing someone creating a post to select a date.
Because I know people will most likely enter the date field in the incorrect format I just wanted to add a slick jquery date picker to this form field.
The one I wanted to use this is one:
https://www.filamentgroup.com/lab/date_range_picker_using_jquery_ui_16_and_jquery_ui_css_framework/Now my question is… how would I go about doing this?
More specifically I also want to ensure that the applicable jquery code will only get called (loaded) when this specific event post type is loaded an not on any other screens in the admin area.
Any help would greatly be appreciated.
Here is what my functions.php file looks like currently:
<?php add_action('init', 'events'); function events() { register_post_type('events', array( 'labels' => array( 'name' => __('Events'), 'singular_label' => __('Event'), 'new_item' => __('Add Events'), 'add_new' => __('Add Event'), 'add_new_item' => __('Add Event'), 'edit' => __('Edit Event'), 'edit_item' => __('Edit this Event'), 'view' => __('View Event'), 'view_item' => __('View Event'), 'search_items' => __('Search Events'), 'not_found' => __('No Events Found'), 'not_found_in_trash' => __('No Event Found in Trash'), ), 'supports' => array( 'title', 'editor', 'author', 'revisions', 'custom-fields', ), 'rewrite' => array( 'slug' => 'events', 'with_front' => false, ), 'can_export' => true, 'show_ui' => true, 'menu_position' => 0-1, 'public' => true, 'query_var' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'capability_type' => 'post', 'hierarchical' => false, )); } add_filter('manage_edit-events_columns', 'add_new_events_columns'); function add_new_events_columns($events_columns) { $new_columns['cb'] = '<input type="checkbox" />'; $new_columns['title'] = _x('Event Title', 'column name'); $new_columns['event_starts'] = _x('Event Starts', 'column name'); $new_columns['event_ends'] = _x('Event Ends', 'column name'); $new_columns['event_type'] = _x('Event Type', 'column name'); $new_columns['author'] = __('Created by'); $new_columns['date'] = _x('Last Action', 'column name'); return $new_columns; } add_action('manage_posts_custom_column', 'manage_events_columns', 10, 2); function manage_events_columns($column_name, $id) { global $wpdb; switch ($column_name) { case 'event_starts': $custom = get_post_custom(); echo $custom['event_start_date'][0]; echo ' @ '; echo $custom['event_start_time'][0]; break; case 'event_ends': $custom = get_post_custom(); echo $custom['event_end_date'][0]; echo ' @ '; echo $custom['event_end_time'][0]; break; case 'event_type': $custom = get_post_custom(); echo $custom['event_type'][0]; break; default: break; } } register_taxonomy("event_types", array("events"), array("hierarchical" => true, "label" => "Event Types", "singular_label" => "Event Type", "rewrite" => true)); add_action("admin_init", "admin_init"); function admin_init(){ add_meta_box("events_meta", "Event Details", "events_meta", "events", "normal", "high"); } function events_meta() { global $post; $custom = get_post_custom($post->ID); $event_start_date = $custom["event_start_date"][0]; $event_start_time = $custom["event_start_time"][0]; $event_end_time = $custom["event_end_time"][0]; $event_organizer = $custom["event_organizer"][0]; $event_contact_email = $custom["event_contact_email"][0]; $event_contact_phone = $custom["event_contact_phone"][0]; $event_registration_notes = $custom["event_registration_notes"][0]; ?> <p><label>Event Date:</label> <input type="date" autocomplete="off" id="datepicker" size="30" name="event_start_date" value="<?php echo $event_start_date; ?>"></p> <p><label>Start Time:</label> <input type="text" autocomplete="off" id="event-field-single" size="30" name="event_start_time" value="<?php echo $event_start_time; ?>"></p> <p><label>Edn Time:</label> <input type="text" autocomplete="off" id="event-field-single" size="30" name="event_end_time" value="<?php echo $event_end_time; ?>"></p> <p><label>Event Organizer:</label> <input type="text" autocomplete="off" id="event-field-single" size="30" name="event_organizer" value="<?php echo $event_organizer; ?>"></p> <p><label>Contact Email:</label> <input type="text" autocomplete="off" id="event-field-single" size="30" name="event_contact_email" value="<?php echo $event_contact_email; ?>"></p> <p><label>Contact Phone #:</label> <input type="text" autocomplete="off" id="event-field-single" size="30" name="event_contact_phone" value="<?php echo $event_contact_phone; ?>"></p> <p><label>Important Notice:</label> <textarea cols="50" rows="5" name="event_registration_notes"><?php echo $event_registration_notes; ?></textarea></p> <?php } ?>
- The topic ‘adding jquery to custom meta box’ is closed to new replies.