Core caps wp/v2 at per_page=100. Your own route has no cap until you write one. This module collects five habits from our plugins that keep REST fast when the data grows.
| Course | WordPress REST API Course ยท Module 7 of 9 ยท Stage 3 "Ship it" |
| Learn | Page-size caps, no_found_rows, update_post_meta_cache, transients for third-party APIs, safe pagination loops |
| How | Real code from 4WP TODO, FAQ, Weather and SEO Helper, query counts before and after, interview questions after every lesson |
Five habits
flowchart LR
H1["min( 100, max( 1, per_page ) )"] --> H2["no_found_rows"]
H2 --> H3["meta in one batch"]
H3 --> H4["transient ยท 1 hour"]
H4 --> H5["20 pages ร 200 rows ยท exit"]
classDef h fill:#fff5ea,stroke:#fca130,color:#1e293b
class H1,H2,H3,H4,H5 h
Fast is not an optimisation at the end. It is five lines you write with the route.
Before โ after
| Before | After Module 7 |
|---|---|
per_page=-1 returns everything | a cap of 100 |
| A total count nobody shows | no_found_rows => true |
| One meta query per post (N+1) | update_post_meta_cache in one batch |
| Weather API called on every page view | a transient for an hour |
You'll be able to answer
- How does WordPress limit collection size on wp/v2, and why must you do it yourself on custom routes?
- What does no_found_rows do in WP_Query?
- How do you avoid N+1 queries when a REST response includes meta?