Opened 3 years ago
Closed 3 years ago
#60563 closed defect (bug) (fixed)
WP_Query::tax_query property could be null
| Reported by: | manooweb | Owned by: | audrasjb |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.5 |
| Component: | Query | Version: | |
| Severity: | trivial | Keywords: | has-patch commit |
| Cc: | Focuses: | docs |
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)
#2
@
3 years ago
- Milestone Awaiting Review → 6.5
- Owner set to
- Status new → accepted
Thanks!
Self assigning for final check and commit.
#3
follow-up:
↓ 4
@
3 years ago
@manooweb quick question: do you have any example of a situation where tax_query could be null?
#4
in reply to: ↑ 3
@
3 years 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
WP_Query::tax_query doc enhancement