728x90

I have problems in pointing to the database in Wordpress. I have tried to include global $wpdb and it does not work. And I have also done PHP include for the wp-load.phpwp-db.php, wp-config.php but still no fix.

It says,

Fatal error: Call to a member function get_results() on a non-object in C:\xampp\htdocs\wordpress\wp-content\themes\cv_test\searchresult_details.php on line 47

Sorry, I'm a beginner in Wordpress development. Any help is appreciated. Thanks.

    include_once('http://localhost/wordpress/wp-config.php');
include_once('http://localhost/wordpress/wp-load.php');
include_once('http://localhost/wordpress/wp-includes/wp-db.php');

function retrieveClientDesc()
{
    global $wpdb;

    $query = "SELECT client_desc FROM wp_client WHERE client_name =  'Cal'";
    $result = $wpdb->get_results($query, OBJECT);



    for($i = 0; $i<=count($result); $i++)
    {
        $clientDesc = ($result[$i]->client_desc);
        echo $clientDesc;
    }

    print_r($result);
}

This is part of the codes. It keeps says my $result section has a fatal error.

    I have had this problem once and this is how i was able to solve it.

    global $wpdb, $table_prefix;
    
    if(!isset($wpdb))
    {
        //the '../' is the number of folders to go up from the current file to the root-map.
        require_once('../../wp-config.php');
        require_once('../../wp-includes/wp-db.php');
    }


      + Recent posts