Opened 6 years ago
Closed 6 years ago
#50463 closed defect (bug) (fixed)
Don't call WP_Query::get_posts() directly
| Reported by: | Chouby | Owned by: | swissspidy |
|---|---|---|---|
| Priority: | normal | Milestone: | 5.5 |
| Component: | Sitemaps | Version: | 5.5 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
Description
WP_Query::get_posts() should not be called directly because the WP_Query constructor calls it indirectly through its call to WP_Query:query().
See: https://github.com/WordPress/WordPress/blob/5.4.2/wp-includes/class-wp-query.php#L3539-L3543 and https://github.com/WordPress/WordPress/blob/5.4.2/wp-includes/class-wp-query.php#L3432
At best calling WP_Query::get_posts() makes a useless second database query. At worst, the results are wrong as the query is not correctly initialized.
Attachments (1)
Change History (5)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
The proposed patch removes the call to
WP_Query::get_posts()and replaces it by directly accessing to$query->posts.