[wp-trac] [WordPress Trac] #63488: Wrong return value for get_category_by_path()
WordPress Trac
noreply at wordpress.org
Wed May 28 09:59:40 UTC 2025
#63488: Wrong return value for get_category_by_path()
--------------------------+------------------------------
Reporter: milana_cap | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version:
Severity: normal | Resolution:
Keywords: has-patch | Focuses: docs
--------------------------+------------------------------
Comment (by SergeyBiryukov):
Hi there, thanks for the ticket.
This is an interesting one. As noted above, `get_term()` can return a
`WP_Error` if either the term ID is empty or the taxonomy does not exist.
So `get_category_by_path()` can return a `WP_Error` via `get_term()`, but
it's not easy to trigger that within normal workflow. I think the only
case would be when the matching category somehow has an empty `term_id`
value, which is technically possible to reproduce by editing the database
or using the `get_terms` filter:
{{{
add_filter( 'get_terms', function( $terms ) {
foreach ( $terms as $key => $term ) {
$terms[ $key ]->term_id = 0;
}
return $terms;
});
var_dump( get_category_by_path( 'uncategorized' ) );
object(WP_Error)#743 (3) {
["errors"]=>
array(1) {
["invalid_term"]=>
array(1) {
[0]=>
string(11) "Empty Term."
}
}
["error_data"]=>
array(0) {
}
["additional_data":protected]=>
array(0) {
}
}
}}}
I also tried unregistering the `category` taxonomy to see if that would
produce a similar outcome, but `unregister_taxonomy()` has a check for
built-in taxonomies, see [36243] / #35227.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63488#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list