I cannot use %s
in my prepared statement.
echo $get_where; // returns: edited = 1
$get_uncontacted_members = $wpdb->get_results(
$wpdb->prepare("SELECT * FROM yc_customers WHERE %s", $get_where)
);
This code returns an empty array. But when I use $get_where
instead of %s
(see code bellow), then it returns all the results from the database.
// This works
echo $get_where; // returns: edited = 1
$get_uncontacted_members = $wpdb->get_results(
$wpdb->prepare("SELECT * FROM yc_customers WHERE edited = 1", $get_where)
);
Why wouldn’t it work with %s
?
WordPress while uses the sprintf() syntax, it actually works like prepared statements. As such you can only pass the value of the column you are querying against, not entire column(s) and values.