WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a custom events page and I want to know how to create a custom meta box to save event dates. I don't want it to be a regular meta box because I will be using this to make a custom search bar so I am guessing I have to save it to MySQL no?

I am lost, as to how I have to go about this. Any ideas?

Thanks in advance.

share|improve this question
up vote 1 down vote accepted

If you're in need of Meta Boxes for WordPress, check out the amazing code in github by jaredatch.

https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress

This allows you to add all sorts of metaboxes to your WP theme (or plugin). Date Picker, file upload, wysiwyg, text areas, text boxes...it's really amazing and saves lots of time.

share|improve this answer
    
Thanks. I love them :)! – Kwame Boame Dec 8 '11 at 9:06

Wordpress comes preloaded with the scripts to do datepickers.

If you dont want to do it with a plugin, create a regular text metabox, then you need to enqueue a custom script in the wordpress admin with jquery-ui and jquery-ui-datepicker dependencies:

function enqueue_date_picker(){
    wp_enqueue_script(
        'field-date', 
        get_template_directory_uri() . '/admin/field-date.js', 
        array('jquery', 'jquery-ui-core', 'jquery-ui-datepicker'),
        time(),
        true
    );  

    wp_enqueue_style( 'jquery-ui-datepicker' );
}

add_action('admin_enqueue_scripts', 'enqueue_date_picker');

Now all we need to do is call the datepicker in our field-date js file:

jQuery(document).ready(function(){
    jQuery('.datepicker').datepicker(); 
});

Notice the .datepicker selector? replace this with an id or class for your meta box input's class/id. Then the datepicker will load once you click on the input - too easy!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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