numberposts? showposts? posts_per_page?

So the documentation on the Codex is pretty clear that showposts is deprecated. But that same documentation mentions nothing of numberposts. Instead, posts_per_page is listed.

But if we turn to the Codex docs for get_posts we see no mention of posts_per_page, instead citing numberposts.

Read More

In post.php we see what’s happening: numberposts is set up as a default (5), but then copied to posts_per_page (unless posts_per_page is set in the args).

So my question is really quite pedantic, but I’m looking to update Codex so I wanted to ask you guys – is there a reason why we wouldn’t want to just encourage posts_per_page across the board, eventually deprecating numberposts? Or am I missing some critical insight here?

Related posts

Leave a Reply

2 comments

  1. In my opinion, deprecating numberposts would not make sense, as numberposts is used to query x amount of posts, whilst posts_per_page is used to denote how many posts per page are being shown during pagination. If you were to deprecate numberposts in favor of simply posts_per_page, then pagination would not exist.

    ie:

    "numberposts" => 50, "posts_per_page" => 10

    a total of 50 posts to query, 10 posts per page, giving 5 pages of 10 posts each.

    removal of numberposts:

    "posts_per_page" => 50

    a total of 50 posts to query, 50 posts per page (since it copies the value of numberposts to posts_per_page), giving 1 page of 50 posts and no pagination.

    Let me know if I’m just reiterating what you’re already aware of, and I’m just slightly confused by the question.

  2. WP_Query class has posts_per_page param, meanwhile get_posts function has the numberposts param. In the get_posts function docs page it states:

    ‘numberposts'(int) Total number of posts to retrieve. Is an alias of $posts_per_page in WP_Query. Accepts -1 for all. Default 5.

    In the get_posts() code reference page in the source code you can see, it uses numberposts value, when posts_per_page is empty, so that’s how it’s an ‘alias’ (or fallback) for it.

    if ( ! empty( $parsed_args[‘numberposts’] ) && empty( $parsed_args[‘posts_per_page’] ) ) {
    $parsed_args[‘posts_per_page’] = $parsed_args[‘numberposts’];

    At least, that’s how i read it.