How can I remove accents from term names before saving them to the database?

        // populate term
        if( empty ($d)) {
        } else {

            foreach ($d as $key=>$name){

                $d_term = $name;

                if ( has_term($d_term, $d_taxonomy)) {  
                // nothing happens
                } else {
                    wp_set_object_terms( $post_id, $d_term, $d_taxonomy, true );


I tried using WP remove_accents function as well as similar php functions like:


with no success.

  • 2
    Please reread your own question, it does not make sense Commented Feb 22, 2016 at 11:52
  • 1
    Can you elaborate precisely on what is happening? "WP adds these names again and again..." is a bit vague... What do you mean? Give us an example of a term with accents, the exact code you are using to sanitize the term, and the exact result e.g. how many times going into the database, etc... is it an infinite loop, is it adding the term 2 times, 10 times and how does a custom field relate to this if you are talking about terms?
    – Adam
    Commented Feb 22, 2016 at 11:56
  • I think this thread will help you: stackoverflow.com/questions/3371697/…
    – Steven
    Commented Feb 22, 2016 at 11:57
  • Sorry for the confusion. Upon saving a post the script checks if the taxonomy has terms. If it doesn't, then the script adds terms to the taxonomy. It works fine, however, if the terms already added to the taxonomy have accented characters, wordpress adds the same terms with accent to the taxonomy. This happens twice.
    – elbatron
    Commented Feb 22, 2016 at 13:02
  • The name of a duplicated term are the same in database, their slugs are different. For example: Damián first saved: Damin, then: Damian.
    – elbatron
    Commented Feb 22, 2016 at 13:09

1 Answer 1


Just thought I'd point out, your call to remove_accent() is incorrect, you are missing the s off of accents.

Example from codex:

$text = "Hoy será un gran día";
echo remove_accents($text);

Echo result: Hoy sera un gran dia

  • I corrected the code in my question - I used the correct call in functions.php, still the names got saved with accents.
    – elbatron
    Commented Feb 22, 2016 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.