在Function.php中,我想检查我的变量是否存在于wordpress数据库的表中,但它不起作用。
global $wpdb;
$count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->pincode_distro1 WHERE pincode = $the_order->shipping_postcode"));
if($count == 1) { echo 'distro 1'}
else { echo 'distro 2'}
答案 0 :(得分:0)
我猜你不需要$ wpdb-> prepare(),尝试过这种方式?
$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->pincode_distro1 WHERE pincode = '$the_order->shipping_postcode'");
答案 1 :(得分:0)
从表名称中删除$wpdb
。代码可以正常工作
来自
$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->pincode_distro1 WHERE pincode = '$the_order->shipping_postcode'");
到
$count = $wpdb->get_var("SELECT COUNT(*) FROM pincode_distro1 WHERE pincode = '$the_order->shipping_postcode'");