#40671 closed defect (bug) (fixed)
Calling get_term() with just ID, then calling it again with ID and a different taxonomy returns the same term
Reported by: | GunGeekATX | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | 4.7.4 |
Component: | Taxonomy | Keywords: | |
Focuses: | Cc: |
Description
I have a category term ID of 29, and calling get_term() with that ID returns the category. However, if get_term() is called again with both ID and 'post_tag' taxonomy, the original category term is returned.
It appears that the $_term variable is not getting cleared out in WP_Term::get_instance() when there is a term already in the cache, so it's always using that term even when the taxonomy does not match.
Some sample code to replicate this:
<?php add_action( 'init', function() { // Use a valid category term to replicate this. $category_term_id = 29; echo '<pre>'; // Shows the correct category term. $term = get_term( $category_term_id ); var_dump( $term ); // Still shows the category term, but should be empty // due to the different taxonomy. $term = get_term( $category_term_id, 'post_tag' ); var_dump( $term ); die(); } );
Working on a patch, bug was originally brought to light by @ninnypants in our company Slack while working on a project.
Attachments (3)
Change History (8)
#2
@
7 years ago
- Milestone changed from Awaiting Review to 4.9
@GunGeekATX Thanks for the ping, and for the ticket + patch. I've confirmed the issue and written a unit test to match. Your suggested fix looks good to me - I'm going to make a minor modification to the order in which it runs, and go with it.
Correct patch without my var_dump