Custom Field Order by Last Name and First Name

I’m looking to find a way to order my query by Last Name first then First Name. I was able to do Last Name although not much luck in the Last Name + First Name part. This is what I came up:

$posts = get_posts(array(
‘post_type’ => ‘soldier’,
‘post_status’ => ‘publish’,
‘posts_per_page’ => 5,
‘meta_key’ => ‘last_name’,
‘orderby’ => ‘meta_value’,
‘order’ => ‘DESC’,
‘meta_query’ => array(
array(
‘key’ => ‘last_name’,
‘orderby’ => ‘meta_value’,
‘order’ => ASC
),
array(
‘key’ => ‘first_name’,
‘orderby’ => ‘meta_value’,
‘order’ => ASC
),
),
‘paged’ => $soldier_paged
)); ?>

Read more here:: Custom Field Order by Last Name and First Name

Leave a Reply

Your email address will not be published. Required fields are marked *