prepare() not working

I agree with @bainternet. You don’t need $wpdb->prepare. There isn’t any user supplied content.

The answer to the question is that to get a wildcard % to pass through prepare you need to double it in your code.

LIKE  '_transient_wb_tt_%%'

Try that or this if you want a good look at the generated query:

var_dump($wpdb->prepare("
    SELECT     option_name
    FROM       %s
    WHERE      option_name
    LIKE       '_transient_wb_tt_%%'
    ",
    'abc')); 
die;

Other than being unnecessary, using $wpdb->prepare like this won’t work. The attempt to use prepare to swap in the tablename will result in a tablename with quotes around it. That is invalid SQL. The query should be simple:

SELECT     option_name
FROM       {$wpdb->options}
WHERE      option_name
LIKE       '_transient_wb_tt_%%'

Leave a Comment