k-isabelle
5/31/2018 - 4:29 PM

Sort an array of objects by object property. Example: Sort Wordpress posts after query

Sort an array of objects by object property. Example: Sort Wordpress posts after query

$the_query = new WP_query( 
  array(
    'posts_per_page'    =>    4,
    'meta_key' => 'featured_facts',
    'orderby' =>  'meta_value_num date',
    'order' => ASC
  )
);
      
function cmp($a, $b)
{
  return strcmp($a->menu_order, $b->menu_order);
}
usort($the_query->posts, "cmp");