0

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?

1

1 Answer 1

0

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 );
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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