Opened 4 years ago
Closed 4 years ago
#50463 closed defect (bug) (fixed)
Don't call WP_Query::get_posts() directly
Reported by: | Chouby | Owned by: | swissspidy |
---|---|---|---|
Milestone: | 5.5 | Priority: | normal |
Severity: | normal | Version: | 5.5 |
Component: | Sitemaps | Keywords: | has-patch |
Focuses: | Cc: |
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.
The proposed patch removes the call to
WP_Query::get_posts()
and replaces it by directly accessing to$query->posts
.