|
| 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