I've created some custom fields in a custom post type using the my-meta-box-class plugin which comes with a built in 'date' type of meta box input. I'm having a hard time ordering my custom posts by date. Is the date in this plugin stored as a strtotime()? If not, how can I slightly modify the plugin to get it to do so. Is that even necessary? Is there an easier way to order the events in my custom post type using what is already there in the plugin?


The 'date' value of 'oderby' parameter does not sort your posts by the date specified into the metabox. It will sort the posts in context with the date when the post has been published.

If you need to sort by your date from a metabox (for custom fields) you can then use the Custom Field Parameters (http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters)


It's not really a plugin it's more of a library/class the plugin file there is just to show off as a demo.

any why when you call the date field you can set the format to a timestamp like this:

$my_meta->addDate($prefix.'date_field_id',array('name'=> 'My Date ', 'format' =>'@'));

you can see a list of valid formats here.

and even better you can define your own validation function to store regular (literal text date) as time using php's strtotime function like this:

//create a class named at_Meta_Box_Validate with a method of validation
if (!class_exists('at_Meta_Box_Validate')){
    class at_Meta_Box_Validate{

        public function date_str_to_time($new){
            return strtotime($new);

and then in your addDate function call that function like this:

$my_meta->addDate($prefix.'date_field_id',array('name'=> 'My Date ','validate_func' => 'date_str_to_time'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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