Skip to content

Conversation

IanDelMar
Copy link
Contributor

get_term_by calls get_terms and get_term, both of which can return a WP_Error object if the taxonomy specified in $args['taxonomy'] (corresponding to the $taxonomy parameter of get_term_by) does not exist. However, get_term_by handles any potential errors from get_term and get_terms by converting them into a false return value, thereby ensuring it never directly returns a WP_Error object.

Removing WP_Error from the return type of get_term_by reflects the actual behaviour of the function.

Closes #284

`get_term_by` calls `get_terms` and `get_term`, both of which can return a `WP_Error` object if the taxonomy specified in `$args['taxonomy']` (corresponding to the `$taxonomy` parameter of `get_term_by`) does not exist. However, `get_term_by` handles any potential errors from `get_term` and `get_terms` by converting them into a `false` return value, thereby ensuring it never directly returns a `WP_Error` object.

Removing `WP_Error` from the return type of `get_term_by` reflects the actual behaviour of the function.

Closes php-stubs#284
@szepeviktor
Copy link
Member

Much better now.

Thank you!

@szepeviktor szepeviktor merged commit 7b5e911 into php-stubs:master Apr 25, 2025
6 checks passed
@IanDelMar IanDelMar deleted the get_term_by branch April 26, 2025 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_term_by does not return WP_Error

2 participants