No new route. Core already has one. A custom post type with show_in_rest gets /wp/v2/faq for free. Your meta can ride along, or stay private. In this module you decide which, on real 4WP FAQ and 4WP TODO code.
| Course | WordPress REST API Course ยท Module 3 of 9 ยท Stage 2 "Build your own" |
| Learn | show_in_rest on post types and taxonomies, register_post_meta / register_term_meta with a schema, auth_callback |
| How | Real code from 4WP FAQ and 4WP TODO, before/after JSON responses, interview questions after every lesson |
Property? Extend. Resource? Own namespace.
flowchart TD
Q{"Is it a property<br/>of a post or term?"}
Q -- "yes" --> E["show_in_rest<br/>register_post_meta"]
Q -- "no, a resource" --> N["own namespace<br/>forwp-faq/v1/settings"]
E --> P{"Should clients see it?"}
P -- "no" --> H["show_in_rest => false<br/>+ auth_callback"]
classDef yes fill:#e8f6f0,stroke:#49cc90,color:#1e293b
classDef no fill:#ebf3fb,stroke:#61affe,color:#1e293b
class E,H yes
class N no
show_in_rest is a publish button. Press it only for data a client should see.
Before โ after
| Before | After Module 3 |
|---|---|
| A new route for every field | "meta": { "answers": [ โฆ ] } on /wp/v2/faq/{id} |
| Meta that anyone can write | sanitize_callback + auth_callback |
| Private notes visible in REST | show_in_rest => false for comment meta |
| Settings forced into a post type | a separate resource in your own namespace |
You'll be able to answer
- How do you expose post meta in the REST API, and what does the schema give you?
- What is auth_callback in register_meta for?
- When is extending wp/v2 the wrong choice?