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.php
, wp-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.
2
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');
}
'WEB > WP(WordPress)' 카테고리의 다른 글
dbDelta( string|array $queries = '', bool $execute = true ) (0) | 2018.04.16 |
---|---|
woocommerce-gateway-offline/woocommerce-gateway-offline.php (0) | 2018.04.16 |
Adding Javascript To WordPress Themes The Right Way (0) | 2018.04.14 |
Woocommerce->add_inline_js is deprecated since version (0) | 2018.04.14 |
Code To Integrate WordPress Media Uploader In Plugin or Theme (0) | 2018.04.10 |