SQL errors when querying for something with apostrophes
Using the wpdb::prepare() method is recommended for creating queries properly and avoiding SQL injection. For a basic solution, use the addslashes() function, but this is not sufficient for preventing SQL injection. See Mysql + php with special characters like ‘(Apostrophe) and ” (Quotation mark).