Sort Authors by last name not working
-
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’;
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Sort Authors by last name not working’ is closed to new replies.