WordPress.org

Ready to get started?Download WordPress

Forums

Sort Authors by last name not working (2 posts)

  1. TrishaM
    Member
    Posted 3 years ago #

    Using the_author_meta to display a list of contributors, along with their photo, description, and website.

    My page works perfectly if I set the order to display_name, but I would rather list by last_name, however when I set the order to last_name nothing at all shows up.

    Here's the piece of code I use to set up the query:

    global $wpdb, $table_prefix; // set global WP vars needed for script
    
    $order = 'display_name'; // set order for users table query
    $user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->users ORDER BY $order"); // query users
    
    foreach($user_ids as $user_id) : // start authors' profile "loop"
    
    $user = get_userdata($user_id); // retrieve author (i.e. user) details
    $level = $table_prefix . 'user_level'; // set 'user_level' usermeta meta_key record
    $user->user_level = $user->$level; // assign 'user_level' property to $users
    $role = $table_prefix . 'capabilities'; // set 'role' usermeta table meta_key record
    $user->role = ( is_array( $user->$role ) ) ? array_keys($user->$role) : array( $user->$role );
    
    $user->role = $user->role[0]; // make sure $user->role is not an array

    Any ideas why it won't work when I set $order = 'last_name';

  2. brix11
    Member
    Posted 3 years ago #

    Did you ever find an answer to your query? I am in the same boat.

Topic Closed

This topic has been closed to new replies.

About this Topic