WordPress.org

Ready to get started?Download WordPress

Forums

PHP Code Widget
[resolved] wpdb doesn't work (4 posts)

  1. hikmatune
    Member
    Posted 1 year ago #

    can someone please tell me why can't get the output from this query?

    <?php
    $user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users" );
    echo "<p>User count is {$user_count}</p>";
    ?>

    http://wordpress.org/extend/plugins/php-code-widget/

  2. Samuel Wood (Otto)
    Tech Ninja
    Plugin Author

    Posted 1 year ago #

    You didn't declare global $wpdb; first.

  3. hikmatune
    Member
    Posted 1 year ago #

    Thanks for the reply Samuel but still no luck. Anyway I could debug the process.

  4. Samuel Wood (Otto)
    Tech Ninja
    Plugin Author

    Posted 1 year ago #

    There's nothing to debug, I already gave you the correct answer. I know this to be true, because I tested it before I gave you that answer.

    You have to declare the $wpdb variable as a global before you use it in the block of code. Then your code will work.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic