[wp-trac] [WordPress Trac] #50463: Don't call WP_Query::get_posts() directly

WordPress Trac noreply at wordpress.org
Wed Jun 24 06:59:46 UTC 2020


#50463: Don't call WP_Query::get_posts() directly
--------------------------+-----------------------------
 Reporter:  Chouby        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Sitemaps      |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 `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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50463>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list