#21275 closed defect (bug) (duplicate)
Insert new term on wp_update_term when multiple taxonomies share term being updated
Reported by: | wonderboymusic | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | major | Version: | 2.3 |
Component: | Taxonomy | Keywords: | has-patch |
Focuses: | Cc: |
Description
This bug, and it is a bug, has had real-world consequences for our site management. Here is the scenario, which I think we are all familiar with:
1) I add a term for post_tag: Brooklyn
2) I add a term for taxonomy, location: Brooklyn
3) I add a term for taxonomy, radio_station: Brooklyn
4) I change the name of my radio_station: Brooklyn's Finest
5) My tag and location are now called: Brooklyn's Finest
This sucks. I have if / else'd a few lines of wp_update_term to take this scenario into account. Here is what it does:
1) checks the number of taxonomies a term belongs to
2) If that number is more than 1:
- stores reference to old_tt_id
- calls wp_insert_term (which wil handle dupe and slug checking, etc)
- updates the term_relationships for posts - old_tt_id becomes new_tt_id generated by wp_insert_term
- calls wp_delete_term on the old term_id which will delete the term cache
- changes the function internal $term_id to whatever wp_insert_term returned
3) If count is not more than one, function runs like normal
The result:
The post_tag and location remain "Brooklyn"
The radio_station is "renamed" to "Brooklyn's Finest"
Here is the code stub you can use to test this:
add_action( 'init', function () { register_taxonomy( 'radio_station', 'post', array( 'labels' => array( 'name' => 'Radio Stations' ) ) ); } );
Dupe of #5809
This is indeed an infuriating bug when you get hit by it. Please have a read through the comments on #5809 and see if your patch fits the bill. Note that any fix won't get in without unit tests.