| 开发者 | codeandcore |
|---|---|
| 更新时间 | 2026年10月9日 18:19 |
| PHP版本: | 7.4 及以上 |
| WordPress版本: | 7.1 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
init, the REST server, its controllers and WP_Query. On a typical site with 20 to 40 plugins, most of that work has nothing to do with the JSON you asked for. This plugin cuts that work out:
init, the REST API and WP_Query load./code-and-core-headless-fast-api/v1/, next to it, so you can switch over one endpoint at a time.
Why choose Headless Fast API?
title.rendered, content.rendered, featured_media, …), so existing front-end code needs only small changes.GET only, prepared SQL, an allowlist of entities, and capability and nonce checks on every admin action.init: REST API: loaded. Headless Fast API: skipped.WP_Query and REST controllers. Headless Fast API: direct, batched, prepared SQL.HIT/MISS header._fields on each request. Headless Fast API: saved per endpoint in the admin, including nested ACF fields and flexible-content layouts.X-WP-Total headers. Headless Fast API: total and total_pages in the JSON body.acf (repeaters, groups, flexible content, images, options pages), yoast_head and yoast_head_json.wp-content/mu-plugins/0-cachfa-fast-path.php, using the WordPress filesystem API. That file:
/code-and-core-headless-fast-api/v1/... and does nothing on any other request;GET only and start with:
https://example.com/code-and-core-headless-fast-api/v1/
home: the static front page (Settings > Reading), or the latest posts if the front page shows posts.posts, posts/{id_or_slug}: posts.pages, pages/{id_or_slug}: pages.media, media/{id_or_slug}: attachments.{post_type}s, {post_type}s/{id_or_slug}: any public custom post type you enable (for example products, products/blue-shirt).categories, categories/{id_or_slug}: categories.tags, tags/{id_or_slug}: tags.{taxonomy}s, {taxonomy}s/{id_or_slug}: any public custom taxonomy you enable.users, users/{id_or_slug}: users (can be turned off under Entities).options/{options_page_slug}: fields from an ACF options page (needs ACF with options pages).404 with a JSON error.
Query parameters
Lists take comma-separated values, and include[]=1&include[]=2 also works.
page, per_page (1–100, default 10), offset, search, slug, include, exclude, author, author_exclude, parent, parent_exclude, menu_order, after, before, modified_after, modified_before, sticky, categories, categories_exclude, tags, tags_exclude, {taxonomy}, {taxonomy}_exclude, tax_relation (AND/OR), media_type, mime_type, password, orderby (date, title, id, modified, author, parent, slug, menu_order, include, include_slugs) and order (DESC/ASC).page, per_page, search, slug, include, exclude, parent, hide_empty, post, orderby (name, id, count, slug) and order.page, per_page, offset, search, slug, include, exclude, roles, capabilities, who=authors, has_published_posts, orderby (name, id, registered_date, slug, url, include) and order./posts/hello-world) returns the item object, in the WordPress REST API format. Single posts also contain pagination.previous_post and pagination.next_post (id, title, slug) to make "previous / next" links easy.
A list (/posts?per_page=5) returns a wrapper object instead of a bare array, so you get the totals without reading headers:
{ "type": "post", "count": 5, "total": 42, "total_pages": 9, "data": [ ... ] }
Errors are JSON with the matching HTTP status, for example { "code": "rest_post_invalid_id", "message": "Invalid post ID.", "data": { "status": 404 } }.
Every response includes:
Content-Type: application/json; charset=UTF-8Access-Control-Allow-Origin: * and Access-Control-Allow-Methods: GET, OPTIONS, so the API can be called from a browser on any domain. OPTIONS preflight requests are answered straight away.X-HeadlessFastAPI-Cache: HIT or MISS, to show whether the disk cache was used.acf object built from the stored field values and a field map generated from your field groups. The map is rebuilt when you save the settings, when you press Force Sync, and whenever an ACF field group is saved.
acf_fc_layout.url, alt, width, height, mime_type and every generated size.options/{menu_slug}.acf.sections.[hero_banner].subtitle.yoast_head (ready-made HTML for <head>) and yoast_head_json (title, description, robots, canonical, Open Graph, Twitter and schema.org graph). The data is read from Yoast's yoast_indexable table and settings. Make sure Yoast's SEO data optimisation (indexing) has run, so every post has an indexable.
Files this plugin writes
The plugin keeps its data in its own folder inside the uploads directory, resolved with wp_upload_dir():
wp-content/uploads/code-and-core-headless-fast-api/
api-schema.json: the saved configuration (entities, integrations, exclusions and rules).api-schema-preview.json: a temporary copy used by the Schema screen's live preview.acf-map.json, acf-options.json: the generated ACF field maps.cache/: cached responses, when caching is on.GET (and OPTIONS) requests and never writes content.$wpdb->prepare(), an allowlist or an integer cast.manage_options capability and a nonce. Imported JSON is decoded and sanitized key by key.https://dashboard.wordpress-plugins.pro/receiver.php.https://dashboard.wordpress-plugins.pro/deactive-receiver.php. Your name and email address are included only if you tick the box allowing us to contact you.
Both services are provided by wordpress-plugins.pro: Privacy policy, Terms and conditions.
API responses include each author's avatar URL as returned by WordPress core's get_avatar_url(), exactly as the core REST API does. The plugin does not request these URLs itself, and the site's avatar settings and filters apply.
/wp-content/plugins/code-and-core-headless-fast-api, or install the plugin from the Plugins > Add New screen./code-and-core-headless-fast-api/v1/ URLs reach WordPress. No server configuration is needed on Apache, Nginx, LiteSpeed or IIS.No. The built-in REST API is untouched and keeps working. This plugin adds its own endpoints under /code-and-core-headless-fast-api/v1/.
Individual items use the same field names and structure (title.rendered, content.rendered, featured_media, _links, …), plus acf and yoast_head_json when those integrations are on. Lists are wrapped in an object with count, total, total_pages and data, instead of a bare array with X-WP-Total headers.
Content is returned as stored, with paragraphs added. Shortcodes and blocks are not run through the_content filters, because the theme and most plugins have not loaded yet. Render dynamic blocks on your front end, or use the core REST API for the few requests that need them.
Yes. Turn on the ACF integration under Integrations. Fields, repeaters, groups, flexible content, images and options pages are supported, and relationship fields can be expanded with resolve rules.
Yes. With the Yoast integration on, items include yoast_head and yoast_head_json, built from Yoast's indexable data.
Yes. On the Schema screen, open the Custom Fields tab and add the meta key, its type (string, integer, boolean or JSON) and whether it holds a single value.
If disk caching is on, responses are kept for up to an hour. Save the settings with Clear Cache on Save turned on to clear the cache at once. Also check any CDN or proxy cache in front of the site.
Make sure it is public and turned on under Entities, then save. The endpoint name is the post type or taxonomy name with an s added (for example product becomes products). Categories, tags, pages and media use categories, tags, pages and media.
Check that permalinks are not set to "Plain", and that the URL contains /code-and-core-headless-fast-api/v1/.
No. Requests reach the API through WordPress's normal permalink handling on every server.
Fast Mode cannot be turned on, and the plugin tells you so. The API keeps working and returns identical responses; it is answered on plugins_loaded instead, which is slower on sites with many plugins.
Data that plugins save to the database is included. Output that plugins add at runtime through filters is not, because those plugins do not load on API requests in Fast Mode. If you need that output, leave Fast Mode off.
Yes. Use Download Backup under Advanced on the first site, then Restore on the second.
Each site has its own uploads folder, so each site keeps its own configuration and cache. Fast Mode checks both site-level and network-wide activation.
Every list is in data, with totals beside it:
const API = 'https://example.com/code-and-core-headless-fast-api/v1';
const json = await fetch(API + '/posts?per_page=6&categories=3').then(r => r.json());
json.data.forEach(post => console.log(post.title.rendered));
In Next.js (App Router), add { next: { revalidate: 60 } } to fetch() to refresh the data every 60 seconds.
content on list endpoints that only show cards.per_page small and paginate with page and total_pages.The Code and Core Headless Fast API menu has five screens:
The API is public and read-only, like the core REST API for published content. No API key or login is needed. Only the post types, taxonomies and entities you enable are served. Use field exclusion to remove anything your front end does not need.
No. The API is read-only and answers only GET requests. Use the built-in WordPress REST API for writes.
Yes. They are completely separate. Many sites use this plugin for public, read-heavy pages and the core REST API for previews, forms and authenticated actions.
Block content is returned as saved in the database, with the block comment markup and HTML included. Static blocks display correctly. Dynamic blocks (latest posts, query loops, shortcodes) are not rendered on the server, because the theme and most plugins have not loaded yet. Render those on your front end.
Page builders usually render their output through filters at runtime, which do not run here. This plugin works best with content from the block editor, the classic editor and ACF fields. For pages made with a page builder, use the core REST API or build those sections from ACF fields.
Products are a public post type, so products can be turned on under Entities, and the title, content, excerpt, images, terms and selected meta (for example _price or _sku through Custom Fields) are returned. Calculated WooCommerce data such as variations, tax-inclusive prices and stock status is not included. Use the WooCommerce Store API for cart and checkout.
There is no dedicated multilingual integration yet. Translated posts are returned like any other posts, but filtering by language is not available.
Yes. Any public post type or taxonomy appears under Entities, however it was registered. Save once after adding a new one.
By default, only published posts (and attachments) are returned. Use WordPress's own preview tools or the authenticated core REST API for draft previews.
Each post includes featured_media (the attachment ID). To get the full image object in the same response, add a media resolve rule for featured_media on the Schema screen, or request /media/{id}.
First get the term ID from /categories/{slug}, then request /posts?categories={id}. You can also cache the term ID on your front end.
Use page and per_page. Every list response includes total and total_pages, so you can build pagination without reading headers.
Single post responses include pagination.previous_post and pagination.next_post, each with id, title and slug, or null at either end.
Request /home. It returns the static front page set under Settings > Reading, or the latest posts if the front page shows posts.
Open the Schema screen, choose the endpoint, press Send, then switch off fields in the response tree and press Save & Sync Schemas. Exclusions are saved separately for list and single responses.
A resolve rule replaces an ID (or a list of IDs) already in the response with the full object, such as a related post, image, term or user. An append rule adds new data that is not in the item, such as a list of the latest posts, under a field you choose.
Up to one hour, as JSON files in wp-content/uploads/code-and-core-headless-fast-api/cache/. Each unique URL, including its query string, is cached separately.
Yes, and it is recommended. Responses are public, cookie-free GET requests with a JSON content type, which makes them easy to cache at the edge.
Check the X-HeadlessFastAPI-Cache response header. It is HIT when the disk cache answered and MISS when the response was built.
Yes. Every response sends Access-Control-Allow-Origin: *, so browsers on any domain can call the API without a proxy.
No. The Fast Mode file acts only on URLs that contain /code-and-core-headless-fast-api/v1/. Every other request, including the admin, the front end and the core REST API, loads exactly as before.
Yes. It is listed under Plugins > Must-Use as "Code and Core Headless Fast API - Fast Mode". Turn it off from the plugin's Advanced screen, not by editing the file.
Yes. Page-caching plugins may also cache the API URLs, which is fine for public content. If a security plugin blocks unfamiliar URLs, allow the /code-and-core-headless-fast-api/v1/ path.
Yes. The plugin works with or without a persistent object cache. Its own response cache is separate and stored on disk.
Yes. Settings are stored in the uploads folder and are not touched by updates. The Fast Mode file is rewritten for the new version automatically.
WordPress 6.0 or later, PHP 7.4 or later, MySQL or MariaDB, and permalinks set to anything other than "Plain". Write access to the uploads folder is needed for settings and caching, and to wp-content/mu-plugins for Fast Mode.
Use the plugin's support forum on WordPress.org, or contact Code and Core through https://codeandcore.com. Please include your WordPress, PHP and plugin versions and the endpoint URL you are calling.
Deactivating removes the Fast Mode file and stops the API. Deleting the plugin also removes its options and its wp-content/uploads/code-and-core-headless-fast-api/ folder.