Change sort order of posts on the calendar

In v0.7, we changed the behavior of the calendar to display posts based on the sort order of your custom statuses. The idea here is that the earliest posts in your workflow are most likely the ones needing the most attention.

If this isn’t the case for you, you can hook into the 'ef_calendar_posts_for_week' filter to sort the posts however you’d like. If you haven’t already, please read the introduction to extending Edit Flow. The code snippet below sorts posts into chronological order; you may need a bit of PHP knowledge to modify it to a different approach.

[sourcecode language=”php”]
<?php
/**
* Change sort order of posts on the calendar
* Take the already sorted posts and sort them again
* based on our own criteria
*
* @see http://editflow.org/extend/change-sort-order-of-posts-on-the-calendar/
*
* @param array $day_posts An array of post objects for the day
* @return array $day_posts Our re-sorted array of post objects
*/
function efx_change_calendar_posts_sort_order( $day_posts ) {

// Load the posts into a temporary array by post_date timestamp for sorting
$tmp_posts = array();
foreach( $day_posts as $post_obj ) {
$post_date_timestamp = strtotime( $post_obj->post_date );
$tmp_posts[$post_date_timestamp] = $post_obj;
}
ksort( $tmp_posts, SORT_NUMERIC );
// Re-load the post objects onto our array of posts
$day_posts = array();
foreach( $tmp_posts as $post_obj ) {
$day_posts[] = $post_obj;
}
return $day_posts;
}
add_filter( ‘ef_calendar_posts_for_week’, ‘efx_change_calendar_posts_sort_order’ );[/sourcecode]