• I am able to query and show all of my users of my site, but now that I can do that, I cannot figure out how to get it to sort using the value that is within the “YIM” field in the user profile.
    I basically just want to sort by Department (which I renamed the YIM field to) but I am not sure how to get that Order By into the code. Anybody out there than can point me in the right direction?

    Here is what I have now:

    <?php
    				$wp_user_search = $wpdb->get_results("SELECT ID, display_name FROM $wpdb->users ORDER BY ID");
    
                    foreach ( $wp_user_search as $userid ) {
                        $user_id       = (int) $userid->ID;
                        $user_login    = stripslashes($userid->user_login);
                        $display_name  = stripslashes($userid->display_name);
                        $user_info     = get_userdata($user_id);
    
                        echo('<tr><td><a href="http://sv:81/?author=' . $user_id . '">' . $user_info->last_name .  "</td>");
                        echo('<td>' . $user_info->first_name . "</a></td>");
                        echo("<td>" . $user_info->yim . "</td><td>" . $user_info->jabber . "</td></tr>");
    
                    }
                    ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • Get the meta data in the query and order by value?

    $wp_user_search = $wpdb->get_results("
    SELECT u.ID, u.display_name, um.meta_value
    FROM $wpdb->users u
    JOIN $wpdb->usermeta um ON um.user_id = u.ID
    WHERE um.meta_key = 'yim'
    ORDER by um.meta_value
    ASC");

    NOTE: There is a function for getting all the users incase you weren’t aware, called get_users_of_blog().

    Thread Starter brackishwaters

    (@brackishwaters)

    Mark,

    Thank you very much for the code snippet. That solved the issue and gave me enough to know where I went wrong.

    I had no idea of that function! If I had known this function last week, it could have saved me a ton of effort. Odd as I searched and searched here at wordpress.org but something like that never came up or I missed it.

    Its great to see that now as I know I will be using this in the future.

    Again, Thank You

    I did have a dig around for a codex page for the function, couldn’t find one(guess i’ll make one at some point), so just gave you the function name.

    Happy i could help though.. 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Able to list all users from wp_users, now how to filter by usermeta?’ is closed to new replies.