This can be done using $args = array( ‘orderby’ => array(‘menu_order’,’title’)) however then you are using a 0 index menu_order (0 menu order goes first) and the first letter of the post title (rather than by say, the last name in the post title). So this is just a function to give a little more control over that ordering
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
//sort our posts by their menu_order then by alpha value function jb_reorder_posts($a, $b){ //First take anyone with a menu order and order then first if($a->menu_order && ! $b->menu_order){ return -1; }else if(! $a->menu_order && $b->menu_order){ return 1; }else if($a->menu_order > $b->menu_order){ return 1; }else if($a->menu_order < $b->menu_order){ return -1; } //if neither person has a menu order, order by last name //$a_last_name = end(explode(' ', $a->post_title)); //$b_last_name = end(explode(' ', $b->post_title)); //return strcmp($a_last_name, $b_last_name); return strcmp($a->post_title, $b->post_title); } //Using WP_Query usort($new_query->posts, 'jb_reorder_posts' ); //Using get_posts() usort($posts, 'jb_reorder_posts' ); |