我需要连接同一主机中的另一个数据库并返回产品值(Woocomece)。返回值为空
add_shortcode(\'product_project_test\', \'product_project_test\');
function product_project_test() {
$mydbTest = new wpdb(\'user\',\'password\',\'dbname\',\'localhost\');
$result= $mydbTest->get_results("SELECT `meta_value` FROM `wp_postmeta` WHERE \'post_id\' = 5338 AND \'meta_key\' = \'_sale_price\'");
$price = $result[0];
$price = number_format($price, 2, \'.\', \',\');
return \'$ \'.$price;
}
SQL Consult
SELECT `meta_value` FROM `wp_postmeta` WHERE `POST_ID` = 5338 AND `meta_key` = \'_sale_price\'
ReturnUpdate - my Solution works
add_shortcode(\'product_project_test\', \'product_project_test\');
function product_project_test() {
$mydbTest = new wpdb($userdb,$mypass,$mydb,\'localhost\');
$query = "SELECT * FROM wp_postmeta WHERE post_id=608 AND meta_key IN(\'_sale_price\', \'_regular_price\')";
$results = $mydbTest->get_results($query, ARRAY_A);
foreach($results as $result){
if($result[\'meta_key\'] == \'_sale_price\'){
$price= $result[\'meta_value\'];
$price= number_format($price, 2, \'.\', \',\');
} else if($result[\'meta_key\'] == \'_sale_price\'){
$old_price= $result[\'meta_value\'];
$old_price= number_format($old_price, 2, \'.\', \',\');
}
};
return \'$ \'.$price;
}