Having trouble with this query. It returns an empty array even though I know the variables are correct and that multiple rows exist in the database that match.

$results_a = $wpdb->get_results(
                        $wpdb->prepare("SELECT * 
                                        FROM $wpdb->custom_table 
                                        WHERE 'FK_show'=%d 
                                            AND 'season`=%d",
  • 1
    what is the value of $wpdb->custom_table?
    – Milo
    Commented Feb 18, 2015 at 20:16
  • 1
    there is a ~ tilda instead of a single quote after 'season'. I have fixed this but same problem is happening.
    – r4gt4g
    Commented Feb 18, 2015 at 20:32
  • the value of $wpdb->custom_table returns 'wp_geasons' (it is the wordpress prefix + a custom table name).
    – r4gt4g
    Commented Feb 18, 2015 at 20:33
  • I generated the following PHP code using MySQL: $sql = "SELECT * FROM wp_gseasons WHERE season=1 AND FK_show=94"; - which are the values for the variables I am using. This query returns 17 results in MYSQL
    – r4gt4g
    Commented Feb 18, 2015 at 20:39
  • both 'FK_show' and 'season' are of type INT(11)
    – r4gt4g
    Commented Feb 18, 2015 at 20:41

1 Answer 1


When the query was done using ~ (tilda) quotes around columns in the SQL instead of the ' it worked. It has something to do with the collation of my tables in MySQL, I believe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.