Got a bit of an issue i’m trying to get solved and haven’t been able to get a query that reflects what I want.

Basically I have a long list of bio’s to click on, they are sorted by last_name, which is an advanced custom field, however, there are a few situations where there are people with the same last name, and so it then needs to order them by their first name as well (acf field called first_name).

Currently the query is

$peopleQuery = new WP_Query(array(
      'post_type' => array('lawyer'),
      'posts_per_page' => -1,
      'orderby' => array('meta_value' => 'ASC'),
      'meta_key' => 'last_name'
    ));

And i’ve tried ordering like this

'orderby' => array(
    'last_name' => 'ASC',
    'first_name' => 'ASC'
)

but to no change. Has anybody ever done this successfully? Is there a way to maybe sort the query how i have it now but then use PHP to order those cases? Any tips or help is greatly appreciated! Let me know if you need any more info.

Read more here: WordPress alpha order by last name, first name


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: