• I am looking to add a simple member counter to my wordpress site. It will just say “there are currently x members”.

    Does anyone know how to achieve this? I dont mind hard coding, as that might be a better option than a plugin. I searched the documentation to no avail.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi,

    As wordpress is storing all the details in database..you can simple execute query on wp_users table and take a desired output.

    Thanks,

    Shane G.

    Thread Starter oste15

    (@oste15)

    Unfortunately that really doesnt help me as I am not a programmer. Maybe you can break that down into lamens terms for me.

    Thanks, I appreciate the help.

    Hi Oste15,

    I’m not much of a programmer either. However, I did find this post in the WordPress Codex that I hope will help.

    <?php
    $user_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users;");?>
    <?php echo 'There are currently ' . $user_count; . ' members.' ?>

    There’s also a similar thread here!

    Thread Starter oste15

    (@oste15)

    That does the trick. I must not have searched hard enough.

    Thanks.

    Excellent! Please mark the thread resolved!

    Thread Starter oste15

    (@oste15)

    actually I used this code:
    <?php
    $user_count = $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->users;”);?>
    <p><?php echo ‘user count is ‘ . $user_count; ?></p>

    which works fine, however when you try to concatenate the word members on the end it gives an error for an undefined .

    I wonder if it is possible to add a word to the end.

    Give this a shot…

    <?php
    $user_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users;");?>
    <p><?php echo('user count is ' . $user_count . ' members'; ?></p>
    Thread Starter oste15

    (@oste15)

    Alright disregard my last post. After a little research on concatenation it is clear we need to do this

    <?php $user_count = $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->users;”);?>
    <p><?php echo “There are currently ” . $user_count . ” members”; ?></p>

    A few more self teachings like that and I might be able to talk more like the second poster on this thread, and less like the poster one up.

    Wow! Just trying to help buddy…

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Add a member counter’ is closed to new replies.