id summary reporter owner description type status priority milestone component version severity resolution keywords cc focuses 52386 Should WP_Query::get_posts be a private method? rebasaurus "Sometimes, users call `WP_Query::get_posts()` incorrectly, as it is a publicly accessible method: {{{#!php get_posts(); }}} Unfortunately, this ends up doing a double query to the DB, as the `WP_Query::get_posts()` is mistaken for a getter when used outside the scope of the constructor. The ideal way to efficiently query would be: {{{#!php posts; }}} ...Or in the case where no arguments are directly passed into a new WP_Query: {{{#!php query( $args ); }}} ''I just want to preface that I actually don't have the historical context behind why `WP_Query::get_posts()` remains a public method (whether it's left for backwards-compatibility reasons or whatnot).'' @jrf suggests a potential approach to this in https://github.com/WordPress/WordPress-Coding-Standards/issues/1860#issuecomment-768296206: > it may be more appropriate to see if this can be solved in WP Core by checking if the $query is the same as previously used and if so, short-circuiting the function to return the previously retrieved results as saved in the $posts property. Would love to see some discussion around this if it can get resolved within WP Core. Thanks!" enhancement new normal Awaiting Review Query normal performance