$wpdb queries no longer work when using multiple % characters – PHP 8.0 issue?
-
Recently, some $wpdb queries have stopped working properly in functions.php. I think the reason might be that I upgraded from PHP 7.4 to PHP 8.
$wpdb->get_var($wpdb->prepare(‘SELECT COUNT(*) id FROM custom_table WHERE field1 LIKE “%s%”‘, $prepare))
The query always returns 0 but it shouldn’t. The issue is the “%s%”. If I change that to “%s” then the query works. But I need the wildcard character %. $wpdb seems to no longer like more than one % in the quote.
A similar query also always returns 0 now. But it shouldn’t. Again the issue is the multiple % in the quote:
$wpdb->get_var($wpdb->prepare(‘SELECT COUNT(*) id FROM custom_table WHERE field1 LIKE “%s%s”‘, $prepare2))
Any suggestions? Thank you
- The topic ‘$wpdb queries no longer work when using multiple % characters – PHP 8.0 issue?’ is closed to new replies.