Every time I see different answer.
Can anyone give me a good reliable answer on the difference between
numberposts, showposts, posts_per_page when querying posts?
They are all the same and does exactly the same thing. Usage are slightly different though
numberposts, posts_per_page and showposts are all valid in get_posts(). numberposts is set to posts_per_page before being passed to WP_Query. Check the source code
if ( ! empty($r['numberposts']) && empty($r['posts_per_page']) )
$r['posts_per_page'] = $r['numberposts'];
posts_per_page and showposts are all valid in WP_Query but numberposts not. If showposts is used, it is set to posts_per_page in the WP_Query class. See the source code
if ( isset($q['showposts']) && $q['showposts'] ) {
$q['showposts'] = (int) $q['showposts'];
$q['posts_per_page'] = $q['showposts'];
}
Although the codex says showposts is depreciated, there is still no depreciation notice in core.It was however replaced in favor of posts_per_page.
To answer your question, posts_per_page is probably the best to use as numberposts and showposts are being set to posts_per_page in the WP_Query class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With