Performance & Caching

Five habits from real plugins: cap the page size, skip the count, batch the meta, cache other APIs, give every loop an exit.

4 lessons16 interview questions

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.

CourseWordPress REST API Course ยท Module 7 of 9 ยท Stage 3 "Ship it"
LearnPage-size caps, no_found_rows, update_post_meta_cache, transients for third-party APIs, safe pagination loops
HowReal 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

BeforeAfter Module 7
per_page=-1 returns everythinga cap of 100
A total count nobody showsno_found_rows => true
One meta query per post (N+1)update_post_meta_cache in one batch
Weather API called on every page viewa 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?

Lessons in this module 4 lessons