WordPress.org

Forums

WP-UserOnline
[resolved] Foreach with get_users_browsing_site? (5 posts)

  1. RevConcept
    Member
    Posted 1 year ago #

    Is there a way to get the get_users_browsing_site data into a foreach?

    I need to append some other data to the list of users that will be output, but right now I can't pull the members apart with this function.

    Thanks!

    https://wordpress.org/plugins/wp-useronline/

  2. Lester Chan
    Member
    Plugin Author

    Posted 1 year ago #

    Try

    $users = UserOnline_Template::compact_list( 'site' , 'list' );

  3. RevConcept
    Member
    Posted 1 year ago #

    Hmmmm...this is what I have:

    $users = UserOnline_Template::compact_list( 'site' , 'list' );
    
    foreach($users as $user) {
        echo $user;
    }

    It returns this error: Catchable fatal error: Object of class stdClass could not be converted to string.

  4. Lester Chan
    Member
    Plugin Author

    Posted 1 year ago #

    the $user is an object not a string, you do a var_dump($user); instead of echo $user; and see what it returns first.

  5. RevConcept
    Member
    Posted 1 year ago #

    Ah, duh ;) Thanks!

    For anyone else wanting to extract this info, here is the beginnings of what I'm setting up in order to grab the user avatar and customize the list.

    if (function_exists('get_users_browsing_site')):
        $users = UserOnline_Template::compact_list( 'site' , 'list' );
            foreach ($users as $user) {
                echo get_wp_user_avatar( $user->user_id, 'thumbnail' );
                echo '<a href="'. get_author_posts_url( $user->user_id ) .'">';
                echo $user->user_name;
                echo '</a>';
            }
    endif;

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic