#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 |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.9 |
| Component: | Taxonomy | Version: | 4.7.4 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
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)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Correct patch without my var_dump