WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

Is there a way to store a custom field value as a datetime so it can be used to order by?

share|improve this question

Yes, you can use jQuery DatePicker and save the date, and use query_post to show the postS in order (code also on github):

//The Query
// exactly than
// or
// dates less than
// query_posts('meta_key=start_date&meta_compare=<=&meta_value='.date("Y-m-d"));
// or
// date mayor than
// query_posts('meta_key=start_date&meta_compare=>=&meta_value='.date("Y-m-d"));

//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
 echo the_title();
 echo "<br />";
endwhile; else:

//Reset Query
share|improve this answer
I would recommend using a timestamp instead if Y-m-d format, as that will easily allow you do add time whenever you wish, also MySQL will be quicker at ordering by a timestamp than it will the MySQL date time format. – Joe Hoyle Aug 22 '10 at 12:14

Your Answer


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.