我对mysql的wpdb查询返回null应该有一个匹配。
global $wpdb;
$popular = $wpdb->get_var("
SELECT COUNT(*)
FROM $wpdb->postmeta AS pm, $wpdb->woocommerce_order_items AS woo
WHERE (woo.order_id = pm.post_id AND pm.meta_value = 142)
");
var_dump($popular);
答案 0 :(得分:0)
可能是您在查询中选择了多个值,而get_var只需要返回一个值。请尝试使用get_results。
答案 1 :(得分:0)
您可以使用此处加入
$popular = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->postmeta AS pm left join $wpdb->woocommerce_order_items AS woo on(woo.order_id = pm.post_id) WHERE pm.meta_value = 142");
var_dump($popular);