Skip to content

Instantly share code, notes, and snippets.

@beaucollins
Created March 4, 2011 17:50
Show Gist options
  • Save beaucollins/855375 to your computer and use it in GitHub Desktop.
Save beaucollins/855375 to your computer and use it in GitHub Desktop.
<?php
query_posts( array(
'post_type' => 'event', // only query events
'meta_key' => 'event_date', // load up the event_date meta
'orderby' => 'meta_value', // sort by the event_date
'order' => 'asc', // ascending, so earlier events first
'meta_query' => array( // restrict posts based on meta values
'key' => 'event_date', // which meta to query
'value' => array('2011-01-01','2011-02-01'), // value for comparison
'compare' => 'BETWEEN', // method of comparison
'type' => 'DATE' // datatype, we don't want to compare the string values
) // end meta_query array
) // end array
); // close query_posts call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment