0

I want to get all buddypress logged in user's ID. for that sake i am using

$bp->loggedin_user->id

But this is not helping.. Please help me to get all logged in user id. Thanks.

closed as off-topic by Pieter Goosen, cybmeta, TheDeadMedic, Mayeenul Islam, Howdy_McGee Dec 24 '15 at 21:15

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

2

This $bp->loggedin_user->id will only give you a single id, of the current logged in user. btw - it also requires use of the $bp global. You don't need to use that global. Use bp_loggedin_user_id() instead.

BuddyPress does not track logged in users. It does not use sessions. It does use timestamps in the database to indicate recent activity. So you could use custom sql to return user ids. For example:

function shahid_get_recent_active() {
    global $wpdb;

    $time = time() - (60 * 10); // current time minus 10 minutes
    $cutoff = date('Y-m-d h:i:s', $time);

    $user_ids = $wpdb->get_col( "SELECT user_id FROM {$wpdb->prefix}bp_activity WHERE type = 'last_activity' AND date_recorded > '$cutoff' " ); 
    var_dump( $user_ids );

}
add_action( 'bp_ready', 'shahid_get_recent_active' );

$user_ids will be an array.

Not the answer you're looking for? Browse other questions tagged or ask your own question.