This question has been posed a few times in various places, but I haven’t found a definative and clear answer. Most solutions involve people saying to disable Magic Quotes on the php.ini file (which I did) or modifying core WP files.
Anyways, the question is this: why is it everytime I use $wpdb->insert or $wpdb->update a slash gets added before any single quote. So for instance:
I’ve eaten strawberries becomes I’ve eaten strawberries
Here’s a sample code I used:
$id = $_POST['id'];
$title = $_POST['title'];
$message = $_POST['message'];
$wpdb->update('table_name', array('id'=>$id, 'title'=>$title, 'message'=>$message), array('id'=>$id))
The same problem was here: WordPress Database Output – Remove SQL Injection Escapes but it was never solved aside from “disable magic quotes”
After spending the day on this, the answer is as follows:
WordPress escapes at the $_POST declaration, not at the actual insert, which is bizarre.
Doing this will mean that WP will not add slashes before any quotes.
a little more info–WordPress decided to make people think they were going crazy by adding ‘magic quotes’ even if you’ve got it turned off starting in version 3.0. Any access to $_REQUEST, $_GET, $_POST, $_COOKIE, or $_SERVER will be affected. See
wp-includes/load.php
.you can use this instead
http://codex.wordpress.org/Function_Reference/stripslashes_deep