Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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'));
share|improve this answer
    
thanks again! :) –  marctain Mar 2 '12 at 17:43
add comment

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)

share|improve this answer
add comment

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.