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.
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.
WordPress already includes 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:
Now all we need to do is call the datepicker in our field-date js file:
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!