Skip to content

Commit ed52f7d

Browse files
authored
Merge pull request #1732 from WordPress/docs/posts-per-page
Docs: Add PostsPerPage XML doc
2 parents 5cc744f + 9eeeb6c commit ed52f7d

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<documentation title="High Posts Per Page Limit">
2+
<standard>
3+
<![CDATA[
4+
Using "posts_per_page" or "numberposts" with the value set to an high number opens up the potential for making requests slow if the query ends up querying thousands of posts.
5+
6+
You should always fetch the lowest number possible that still gives you the number of results you find acceptable.
7+
]]>
8+
</standard>
9+
<code_comparison>
10+
<code title="Valid: posts_per_page is not over limit (default 100).">
11+
<![CDATA[
12+
$args = array(
13+
'posts_per_page' => <em>-1</em>,
14+
);
15+
$args = array(
16+
'posts_per_page' => <em>100</em>,
17+
);
18+
$args = array(
19+
'posts_per_page' => <em>'10'</em>,
20+
);
21+
22+
$query_args['posts_per_page'] = <em>100</em>;
23+
24+
_query_posts( 'nopaging=1&posts_per_page=<em>50</em>' );
25+
]]>
26+
</code>
27+
<code title="Invalid: posts_per_page is over limit (default 100).">
28+
<![CDATA[
29+
$args = array(
30+
'posts_per_page' => <em>101</em>,
31+
);
32+
33+
$query_args['posts_per_page'] = <em>200</em>;
34+
35+
_query_posts( 'nopaging=1&posts_per_page=<em>999</em>' );
36+
]]>
37+
</code>
38+
</code_comparison>
39+
<code_comparison>
40+
<code title="Valid: numberposts is not over limit (default 100).">
41+
<![CDATA[
42+
$args = array(
43+
'numberposts' => <em>-1</em>,
44+
);
45+
$args = array(
46+
'numberposts' => <em>100</em>,
47+
);
48+
$args = array(
49+
'numberposts' => <em>'10'</em>,
50+
);
51+
52+
$query_args['numberposts'] = <em>'-1'<em>;
53+
54+
_query_posts( 'numberposts=<em>50</em>' );
55+
]]>
56+
</code>
57+
<code title="Invalid: numberposts is over limit (default 100).">
58+
<![CDATA[
59+
$args = array(
60+
'numberposts' => <em>101</em>,
61+
);
62+
63+
$query_args['numberposts'] = <em>'200'</em>;
64+
65+
_query_posts( 'numberposts=<em>999</em>' );
66+
]]>
67+
</code>
68+
</code_comparison>
69+
</documentation>

0 commit comments

Comments
 (0)