WP_Query – Order by multiple custom fields

The Code

$args = array(  'post_status' => 'publish', 'post_type' => 'board', 'meta_query' => array( 
 'last_name' => array('key' => 'last_name'),     
 'first_name' => array('key' => 'first_name'),   
),
'orderby' => array( 'last_name' => 'ASC', 'first_name' => 'ASC' ), 'nopaging' => true  ); 
$query = new WP_Query( $args ); 
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
...

Always call wp_reset_postdata() afterwards to reset the global $post value. Otherwise, any attempt to retrieve data from the page will return null.

Do NOT follow this link or you will be banned from the site!