Creating a Post, can authors be ordered by last name?

When I create a post, the author dropdown/select seems to order authors by the first letter of the full display name.

Is there a bit of code for functions.php that would order this dropdown by last name?

1 Answer
1

Here’s one example how we can modify the order of users in the dropdowns on the post.php and post-new.php pages (PHP 5.4+):

/**
 * wp_dropdown_users - modify ordering on post.php and post-new.php
 */
add_filter( 'wp_dropdown_users_args', function( Array $query_args, Array $args )
{
    // Nothing to do if we're not on post.php and post-new.php
    if( ! did_action( 'load-post.php' ) && ! did_action( 'load-post-new.php' ) )
        return $query_args;

    // Modify the user query - Adjust to your needs!
    $query_args['meta_key'] = 'last_name';
    $query_args['orderby']  = [ 'meta_value' => 'ASC', 'display_name' => 'ASC' ];

    return $query_args;

}, 10, 2 );

Here we query users that have the last_name meta key and order first by the last_name and then display_name.

Hope you can adjust it to your needs!

Leave a Comment