I can’t seem to get my head around how wordpress insert new tags into the terms table. I want to copy this behaviour in a plugin, and send the tags to a different table then wordpress’ native terms table.
I’m writing a social tagging plugin for WordPress (allows readers to submit their tags for posts). For this I need new tables in the db to store the user submitted tags in. I already have this working, but the tags aren’t stored correctly (can’t use WordPress’ native function to store tags because it needs to go to a different table).
WordPress stores foto’s as foto’s (dutch plural of photo), whereas my plugin stores it as foto\’s. Is there any way to prevent this?
First, check to see whether or not the incoming tag has the slashes on it, before you stuff it into the database. The reason I say this is that WordPress automatically adds slashes to incoming content. This then gets slashed again when you run it through the database functions (this is called escaping), so you get that extra slash in there.
So, check to see if your incoming tag data from $_GET or $_POST has the slashes already in it. If so, then run it through the PHP stripslashes() function before passing it to the database functions. If you’re using WordPress’ database functions (specifically, the $wpdb->insert($table, $data) function call), then it will handle sanitizing it properly for you.