WRONG SQL SYNTAX
-
All of your direct
$wpdbquery calls are incorrect. If you’re doing a select from a specific table, you should be using the$wpdbglobal, not specificallywp_commentsorwp_postmetaExample your incorrect code:
$most_sell_courses = $wpdb->get_results( "SELECT 'meta_value', 'post_id' FROM 'wp_postmeta' WHERE 'meta_key' LIKE '%total_sales%' and meta_value > 0", OBJECT );Correct code:
$most_sell_courses = $wpdb->get_results( "SELECT 'meta_value', 'post_id' FROM $wpdb->postmeta WHERE 'meta_key' LIKE '%total_sales%' and meta_value > 0", OBJECT );Basically anywhere you are specifically using
wp_XXXyou need to use$wpdb->prefixor just directly call$wpdb->XXX… reason being, if the standardwp_prefix is not used, your plugin will not function at all.See documentation:
https://codex.ww.wp.xz.cn/Class_Reference/wpdb
The topic ‘WRONG SQL SYNTAX’ is closed to new replies.