Last active
January 27, 2017 12:49
-
-
Save mohsinr/0322850115acec978c109afc52c6f388 to your computer and use it in GitHub Desktop.
WordPress Taxonomies , Remove Trailing And Leading Spaces from Terms' Names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
Need to run this code just ONCE, | |
so remove it after one pageload once spaces are removed | |
**/ | |
# List of Taxonomies with terms which have leading spaces | |
$taxos = array('rooms', 'settings', 'views', 'features'); | |
foreach ($taxos as $taxo) { | |
$terms = get_terms( array('taxonomy' => $taxo, 'hide_empty' => false) ); | |
foreach ($terms as $term) { | |
# Need to convert hidden spaces into html entities for easy find/replace | |
$name = htmlentities($term->name, null, 'utf-8'); | |
$name_new = preg_replace("/ /",'',$name); | |
wp_update_term( $term->term_id, $taxo, array( | |
'name' => $name_new | |
) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment