Can’t pass table to $wpdb->prepare

The prepare() method escapes %s. The second piece of code you listed breaks because quotation marks are added to the table name, hence it doesn’t match what’s in the DB.

The first piece of code works because it’s a straight string replacement hence matching the name of the table in the database.

What is the error message you are getting?

HTH

Leave a Comment