Created
January 18, 2011 01:11
-
-
Save collegeman/783830 to your computer and use it in GitHub Desktop.
Sort two WordPress posts by the value of a meta key, "event-date," assumed to be a string parseable by strtotime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sort_by_event_date($post1, $post2) { | |
| $date1 = strtotime(get_post_meta($post1->ID, 'event-date', true)); | |
| $date2 = strtotime(get_post_meta($post2->ID, 'event-date', true)); | |
| // I've reversed this now so that it sorts in descending order, newest first: | |
| return ($date1 == $date2) ? 0 : ($date1 > $date2 ? -1 : 1); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment