Opened 10 years ago
Closed 10 years ago
#29911 closed defect (bug) (fixed)
Deleting a term does not invalidate cache for child terms
Reported by: | boonebgorges | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Taxonomy | Keywords: | needs-patch good-first-bug |
Focuses: | Cc: |
Description
See #29614.
Steps to reproduce:
- Create a $term in a hierarchical taxonomy
- Create a $child_term with parent=$term
- wp_delete_term( $term )
- Fetch cached version of $child_term with get_term(). 'parent' is still $term.
Unit test attached.
Two options to fix:
- During deletion, run a query to get term_ids of all child terms, then run each through
clean_term_cache()
. - During deletion, instead of doing a direct DB query to change the parent, run each item through
wp_update_term()
.
Option 2 is much more aesthetically pleasing, but in cases where a parent has hundreds of children, there could be scaling issues, as separate DB queries would be run for each. Could use some testing, and a patch.
Attachments (2)
Change History (7)
This ticket was mentioned in IRC in #wordpress-dev by DrewAPicture. View the logs.
10 years ago
#3
@
10 years ago
I was able to replicate the issue, and my initial tests resolved it with this patch resolved it.
I noticed from the documentation, that clean_term_cache can accept an array of IDs, so I ran it once using the $edit_tt_ids variable instead of a foreach loop, as is done on the clean_post_cache.
Note: See
TracTickets for help on using
tickets.
Option 1 is what we do for posts. See wp_delete_post(). Very simple and straightforward.