• I have implemented the shortcode for listing group members by ID on a WP page (as per the script on https://www.ads-software.com/support/topic/plugin-user-groups-list-group-members). But i’m wanting to sort the members listed by surname.

    How do I do that?
    Is someone able to modify the code to make it possible?

    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='group-list'> <ul>";
            foreach( $userIDs as $userID ) {
                $user = get_user_by('id', $userID);
                $content .= "<li>";
                $content .= get_avatar( $user->ID, 70 );
                $content .= "<h3>" . $user->display_name . "</h3>";
                $content .= "<p><a href='". get_author_posts_url( $user->ID ) . "' class='more-info-icon'>More info</a>";
                $content .= "<!-- add more here --></p>";
                $content .= "</li>";
            }
            $content .= "</ul></div>";
        } else {
            $content =
            "<div class='group-list group-list-none'>Returned no results</div>";
    
        }
        return $content;
    }

    https://www.ads-software.com/plugins/user-groups/

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Listing group members by surname’ is closed to new replies.