widget_users modification

Hi,

I have the widget-users running on newly created blogs.

The widget runs fine except that it shows sitewide users.

However, I would like to be able to show ONLY users from the associated blog.

(i.e blog1 users shown on blog1, blog2 users shown on blog2, etc)

What change would I have to make to the following code to make this happen?

// $query = “SELECT ID, display_name FROM ” . $wpdb->base_prefix . “users WHERE spam != ‘1’ ORDER BY user_registered DESC LIMIT ” . $options; //

Thanks

Ray

  • Andrew
    • Champion of Loops

    It’s not really a simple modification I’m afraid. You’ll need to do one of the following:

    1) Use the get_users_of_blog() function to pull the users on a blog

    2) Switch the query over to the usermeta table instead of the users table (or do a JOIN)

    Either way it’s more than a one or two line edit. If a fair number of users are interested we can look into a Blog Users Widget.

    Thanks,

    Andrew

  • romenzo
    • WPMU DEV Initiate

    I was able to get this widget to display ONLY the users of the blog by changing this line:

    // $query = “SELECT ID, user_login FROM ” . $wpdb->base_prefix . “users WHERE spam != ‘1’ ORDER BY user_registered DESC LIMIT ” . $options; //

    to this one instead:

    // $query =”SELECT ID, user_login FROM $wpdb->users, $wpdb->usermeta WHERE $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = ‘”.$wpdb->prefix.”capabilities’ ORDER BY user_login”;

    I hope this helps someone as this is a really useful widget to have.

    Ray