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

I have 3 meta fields related to dates:

  • year = 2012
  • release_date = 14 November 2012
  • release_date_db = 20121114

I need to show the posts from year 2012 sorted by release_date.

I made this:


How can I order posts by release_date or release_date_db?

share|improve this question
This helped me to get it working – secretja Oct 3 '12 at 22:03

You can do this by just looking for release_date_db:

function plugin_name_get_posts() {
    global $wpdb;
$the_posts = $wpdb->get_results( "SELECT * FROM $wpdb->posts, $wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND meta_key = 'release_date_db' AND meta_value >= 20120000 AND meta_value <= 20121231 ORDER BY meta_value ASC;", ARRAY_A );
share|improve this answer

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.