Change taxonomy slug in database

admin2025-01-07  5

I am using Events Calendar Pro and due to a bug multiple Venue taxonomies were created. For example, I have museum, museum-2, etc. I would like to delete the duplicates but assign the event associated with the duplicate venue to the 'main' venue. Is there a find/replace I can use that would do this for me? Other suggestions are welcome. Thank you.

I am using Events Calendar Pro and due to a bug multiple Venue taxonomies were created. For example, I have museum, museum-2, etc. I would like to delete the duplicates but assign the event associated with the duplicate venue to the 'main' venue. Is there a find/replace I can use that would do this for me? Other suggestions are welcome. Thank you.

Share Improve this question asked Jan 29, 2013 at 19:41 ellajellaj 11
Add a comment  | 

1 Answer 1

Reset to default 0

You could just run DELETE FROM wp_terms WHERE slug LIKE "museum-%" on you MySQL server, but that would probably leave some orphan rows in wp_term_taxonomy and potentially in wp_term_relationships if you have used the terms. While being a bit more complicated I would recommend deleting them using the WordPress API. Something like this might work (from memory, so I'm not 100 percent on the usage of the term_ prefix in $term->term_slug and $term->term_id):

$terms = get_terms(array('your_term'), array('name__like' => 'Museum'));
foreach ($terms as $term) {
    if (term->term_slug != 'Museum') {
        wp_delete_term($term->term_id, 'your_term');
    }
}

It's apparently not possible to search for terms by slug, so be carful not to delete terms like "Museums" or "Museum of Natural History" which will happen if you run the above code.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736256839a393.html

最新回复(0)