我的代码有什么问题?它不获取计数,但正在插入数据库。
function r_rate_recipe()
{
global $wpdb;
$output = array(\'status\' => 1);
$post_id = absint($_POST[\'rid\']);
$rating = round($_POST[\'rating\'], 1);
$user_ip = $_SERVER[\'REMOTE_ADDR\'];
$rating_count = $wpdb->get_var(
"SELECT COUNT(*) FROM \'" . $wpdb->prefix . "racipe_ratings\'
WHERE recipe_id=\'" . $post_id . "\' AND user_ip=\'" . $user_ip . "\'"
);
if ($rating_count > 0) {
wp_send_json($output);
}
$wpdb->insert(
$wpdb->prefix . \'racipe_ratings\',
array(
\'recipe_id\' => $post_id,
\'rating\' => $rating,
\'user_ip\' => $user_ip
),
array(\'%d\', \'%f\', \'%s\')
);
$output[\'status\'] = 2;
wp_send_json($output);
}