• Resolved AndreiD

    (@andreiro37)


    I have a global variable global $online_users to display the number of users on site.
    – how do i get only the number?
    – which hook should i use (this one doesnt display)
    thanks

    add_action(‘plugins_loaded’, ‘nr_online_users’);
    function nr_online_users(){
    global $online_users;

    if ( function_exists(‘users_online’) ) {
    $online_users = users_online();

    return $online_users; // (int)
    } else {
    return “no users”;
    }
    }`

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter AndreiD

    (@andreiro37)

    I mean useers logged-in, not guests.

    Plugin Author Lester Chan

    (@gamerz)

    you can try

    
    global $wpdb;
    $logged_in_users = $wpdb->get_var( "SELECT COUNT(*) FROM wp_useronline WHERE user_type = 'member'" );
    

    Hi,

    Where do you put this code? I’m interested in the same functionality.

    Thread Starter AndreiD

    (@andreiro37)

    function my_theme_online_users_cb( $atts, $content = "" ){
       global $wpdb;
    
       $online_users = $wpdb->get_var( "SELECT COUNT(*) FROM wp_useronline WHERE user_type = 'member'" );
    
       return $online_users;
    }
    add_shortcode( "my_theme_online_users", "my_theme_online_users_cb" );

    To display:

    1. php code
    <?php echo do_shortcode("[my_theme_online_users]"); ?>

    2. or insert in wp admin editor
    [my_theme_online_users]

    thanks!

    • This reply was modified 7 years, 4 months ago by AndreiD.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to display only number of online users’ is closed to new replies.