I've this error "Call to a member function get_results() on a non-object in" from this code:
require_once($_SERVER['DOCUMENT_ROOT'] . $folder . '/wp-config.php');
require_once($_SERVER['DOCUMENT_ROOT'] . $folder . '/wp-load.php');
if (!$wpdb) {
$wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
} else {
global $wpdb;
}
function vendorDatails( $param)
{
if ((substr ($param, 0, 0)) == '#')
{
substr($param, 1);
}
$order_ids = $wpdb->get_results(
"
SELECT DISTINCT vendor_id
FROM $wpdb->lqrhxf_pv_commission
WHERE order_id = %d
",
$param
);
foreach ( $order_ids as $order_id )
{
echo $order_id->vendor_id;
}
}
The db parameters are loaded successfully but I've the error on the line above when I use $wpdb variable:
$order_ids = $wpdb->get_results(