[wp-trac] [WordPress Trac] #21275: Insert new term on wp_update_term when multiple taxonomies share term being updated
WordPress Trac
wp-trac at lists.automattic.com
Sat Jul 14 22:52:06 UTC 2012
#21275: Insert new term on wp_update_term when multiple taxonomies share term being
updated
----------------------------+-----------------------------
Reporter: wonderboymusic | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 2.3
Severity: major | Keywords: has-patch
----------------------------+-----------------------------
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[[BR]]
2) I add a term for taxonomy, location: Brooklyn[[BR]]
3) I add a term for taxonomy, radio_station: Brooklyn[[BR]]
4) I change the name of my radio_station: Brooklyn's Finest[[BR]]
5) My tag and location are now called: Brooklyn's Finest[[BR]]
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[[BR]]
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:[[BR]]
The post_tag and location remain "Brooklyn"[[BR]]
The radio_station is "renamed" to "Brooklyn's Finest"[[BR]]
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' )
) );
} );
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21275>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list