[wp-trac] [WordPress Trac] #42771: WP_Term::get_instance() regression for non-category terms queried with 'category' taxonomy
WordPress Trac
noreply at wordpress.org
Fri Dec 1 18:09:03 UTC 2017
#42771: WP_Term::get_instance() regression for non-category terms queried with
'category' taxonomy
--------------------------+-----------------------------
Reporter: markjaquith | Owner:
Type: defect (bug) | Status: new
Priority: high | Milestone: Awaiting Review
Component: Taxonomy | Version: 4.9
Severity: major | Keywords:
Focuses: |
--------------------------+-----------------------------
`WP_Term::get_instance()` changed in 4.9 which caused a lot of other
issues, probably including:
#42717
#42691
#42605
#42732
Other reports here:
https://wordpress.org/support/topic/category-description-broken-
after-4-9-update/
https://wordpress.org/support/topic/4-9-get_category_link-not-working/
What seems to be happening is this:
Some old category function gets called on a `term_id` that does not exist
as a category (let's say `123`).
e.g. `get_category_link( 123 );`.
This ends up calling `WP_Term::get_instance( 123, 'category' );`
This worked before 4.9, because when the taxonomy failed to match...
{{{
if ( ! $_term || ( $taxonomy && $taxonomy !== $_term->taxonomy ) ) {
}}}
...`$_term` would be left alone.
But in 4.9, this happens:
{{{
// If there isn't a cached version, hit the database.
if ( ! $_term || ( $taxonomy && $taxonomy !== $_term->taxonomy ) ) {
// Any term found in the cache is not a match, so don't use it.
$_term = false;
}}}
The query runs, but it won't find a taxonomy match when iterating the
results, and thus will return false.
The old behavior seems... undesirable. You're querying a `category` term
and potentially getting back a term with another taxonomy.
We could fix most of the cases in the wild by exempting `category` from
the `$_term = false;` bailout. But then we're just perpetuating `category`
being a special case.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42771>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list