[wp-trac] [WordPress Trac] #40671: Calling get_term() with just ID, then calling it again with ID and a different taxonomy returns the same term
WordPress Trac
noreply at wordpress.org
Thu May 4 21:13:38 UTC 2017
#40671: Calling get_term() with just ID, then calling it again with ID and a
different taxonomy returns the same term
--------------------------+-----------------------------
Reporter: GunGeekATX | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 4.7.4
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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
<?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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40671>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list