Opened 2 years ago
Closed 23 months ago
#60563 closed defect (bug) (fixed)
WP_Query::tax_query property could be null
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.5 | Priority: | normal |
| Severity: | trivial | Version: | |
| Component: | Query | Keywords: | has-patch commit |
| Focuses: | docs | Cc: |
Description
By verifying a third party plugin code with PHPStan tool and WordPress stubs, it occurs that in some context WP_Query::tax_query property could be null.
The joined patch propose to enhance the WP_Query::tax_query documentation.
Attachments (1)
Change History (9)
#1
@
2 years ago
- Component changed from General to Query
- Focuses docs added
- Keywords has-patch added
#2
@
2 years ago
- Milestone changed from Awaiting Review to 6.5
- Owner set to audrasjb
- Status changed from new to accepted
Thanks!
Self assigning for final check and commit.
#3
follow-up:
↓ 4
@
2 years ago
@manooweb quick question: do you have any example of a situation where tax_query could be null?
#4
in reply to:
↑ 3
@
23 months ago
Replying to audrasjb:
@manooweb quick question: do you have any example of a situation where
tax_querycould benull?
It isn't so easy to reply.
If I'm not mistaken, I saw tax_query is set only in some conditions by calling WP_Query::parse_tax_query() in WP_Query::parse_query() or WP_Query::get_posts(). So it's possible that this property isn't set and instantiate because WP_Query::parse_tax_query() isn't executed.
https://github.com/WordPress/WordPress/blob/6.4.3/wp-includes/class-wp-query.php#L1372
It's simply a documentation proposition.
When we try to access to the global variable $wp_query (or $wp_the_query) we have no chance to know the tax_query property has been set yet because this property isn't set by the WP_Query instantiation but during the WP_Query::get_posts() execution.
I hope it's clearer.
WP_Query::tax_query doc enhancement