我在指向Wordpress中的數據庫時遇到問題。我試圖包含全局$ wpdb,它不起作用。而且我也爲PHP編寫了wp-load.php
,wp-db.php
,wp-config.php,但仍然沒有解決。
它說,
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
對不起,我在WordPress的發展初學者。任何幫助表示讚賞。謝謝。
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);
}
這是代碼的一部分。它一直說我的$結果部分有一個致命的錯誤。
您可以在這裏放置您的代碼嗎? –
嗨,Merianos,代碼添加。 – crank