I have custom tables in the database i.e. g_projects
with loads of columns. Data is stored in the table using the Wordpress native insert query i.e. $wpdb->insert
, hence they are escaped.
For example
Input: Application's Document
Database: Application\'s Document
The problem is how can I perform search on the escaped columns because they are stored as "Application\'s Document" whereas, I want to be able to search as "Application Document".
My query below returns nothing:
$wpdb->query("SELECT * FROM g_projects WHERE type=\"Application's Document\"");
Edit #1
I am using POSTMAN add-on to call my API which then uses $wpdb->insert()
method to insert new records. Upon further investigation I observed that the slashes were actually added by the POSTMAN
somehow because If I pass data to API using POSTMAN
it stores escaped strings. Whereas, if I use the $wpdb->insert()
directly it will store string without slashes as suggested below by @TheDeadMedic
Edit #2
This is the final edit for those who faced similar problems using POSTMAN. POSTMAN actually escapes string before passing to the $wpdb->insert()
function. Therefore, use $wpdb->unslash()
on the $data before passing to the insert function.
$wpdb->insert( $table, $data )
will already do for you. – TheDeadMedic Sep 23 '15 at 13:53Application's Document
, notApplication\'s Document
. – TheDeadMedic Sep 23 '15 at 14:41