Skip to:
Content
Pages
Categories
Search
Top
Bottom

Echo logged in user count

  • @boriskamp1991

    Participant

    Hi guys!

    How can I get the count of all the logged in users at the moment?
    I need the count so I can echo it along with other site stats on the front-end.

    Thanks!

Viewing 1 replies (of 1 total)
  • @shanebp

    Moderator

    BP doesn’t track who is logged-in.
    It does track last_activity which is based on actually doing something on the site – not just being logged-in and having the site open in a browser.

    So the best you can do is to show a number based on the number of members with last_activity within the last x minutes.

    Try:

    function boris_online_number( ) {
    	global $wpdb;
    	
    	$time = date('Y-m-d H:i:s', time() - ( 15 * 60) );  // minutes * seconds
    	
    	$a_number = $wpdb->get_var( "SELECT COUNT(user_id) FROM {$wpdb->prefix}bp_activity WHERE component = 'members' AND date_recorded > '$time' ");
    	
    	echo 'Online: ' . $a_number;
    }
    add_action( 'bp_ready', 'boris_online_number' );
Viewing 1 replies (of 1 total)
  • The topic ‘Echo logged in user count’ is closed to new replies.
Skip to toolbar