List users by username or surname?
-
Hi There,
I’m using the plugins user-list and user-groups and i managed to list the users per group using shortcodes found on the following site:
https://www.ads-software.com/support/topic/plugin-user-groups-list-group-members?replies=7
I changed the code that was pasted in functions.php a little bit and added css to it so the users would show up in avatars and names next to eachother.
The only problem i have is that the users are listed by ID and not by username of surname, so the aren’t alphbetic at the moment.
Is there anyone how knows how to change the code beneath so the user lists show by username of surname?
Thanx in advance!
Code:
// Grouplist voor de plugin User Groups dmv shortcode [group-list group="NameOfGroup"] add_shortcode('group-list', 'my_group_list_shortcode'); function my_group_list_shortcode( $atts ) { // Get the global $wpdb object global $wpdb; // Extract the parameters and set the default extract ( shortcode_atts( array( 'group' => 'No Group' // No Group is a defined user-group ), $atts ) ); // The taxonomy name will be used to get the objects assigned to that group $taxonomy = 'user-group'; // Use a dBase query to get the ID of the user group $userGroupID = $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM {$wpdb->terms} t WHERE t.name = %s", $group)); // Now grab the object IDs (aka user IDs) associated with the user-group $userIDs = get_objects_in_term($userGroupID, $taxonomy); // Check if any user IDs were returned; if so, display! // If not, notify visitor none were found. if ($userIDs) { $content = "<div class='entry clearfix'>"; foreach( $userIDs as $userID ) { $user = get_user_by('id', $userID); $content .= "<div class='group-list'>"; $content .= get_avatar( $user->ID, 70 ); $content .= "" . $user->display_name . ""; $content .= "</div>"; } $content .= "</div>"; } else { $content = "<div class='group-list group-list-none'>Geen resultaten zichtbaar</div>"; } return $content; }
I use the following shortcode in my article:
[group-list group="GROUPNAME"]
Hope someone kan help me!
- The topic ‘List users by username or surname?’ is closed to new replies.