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 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:

query_posts('meta_key=year&meta_value=2012&order=ASC&posts_per_page=7');

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

1 Answer 1

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

 
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.