WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wpdb and include() questions (3 posts)

  1. drlithium
    Member
    Posted 1 year ago #

    hi, I am new to WP programming and I am confused about how to properly use the WP include files and how to use $wpdb.

    I'd like to call get_user_by() and wp_check_password() from a PHP script that runs standalone. That is, the script is not invoked by any of my wordpress pages.

    I figure I'll just include whatever file that's missing, so I ended up adding the following one by one:

    require_once('wp-includes/plugin.php');
    require_once('wp-includes/pluggable.php');
    require_once('wp-includes/capabilities.php');
    require_once('wp-includes/formatting.php');
    require_once('wp-includes/cache.php');

    and then I hit the wall -- Fatal error: Call to a member function get() on a non-object in /home6/mymuscl3/public_html/wp-includes/cache.php on line 113

    ok, wrong approach. After reading up the documentation of get_user_by(), I discovered $wpdb. So I guess I am supposed to do this:

    require_once('wp-includes/wp-db.php');
    globalize $wpdb;

    but the thing is, wp-db.php only defines the wpdb class. Where is the global variable $wpdb declared? Should I use wpdb(...) as a constructor directly? And if so, how to use $mywpdb = wpdb(...) to call get_user_by()?

  2. drlithium
    Member
    Posted 1 year ago #

    oops, silly me. a look into index.php revealed it all

  3. ssoulless
    Member
    Posted 1 year ago #

    great!!!! i was jsut needing the same =D

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags