Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 152 Vote(s) - 3.66 Average
  • 1
  • 2
  • 3
  • 4
  • 5
numberposts, showposts, posts_per_page. What's the difference?

#1
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?
Reply

#2
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()`][1]. `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

[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through