Structured fields
Post fields (CPT meta)
GCB Lite's field system isn't just for blocks. The same typed controls can attach to a custom post type as a meta-box. The author edits structured fields next to (or instead of) the post body; you read the result from REST as typed JSON.
Useful for content that's a record, not a page — testimonials, brands, team members, projects, FAQ items. The CPT is just rows; the fields are the columns.
Register fields on a CPT
In your theme's functions.php:
add_action('init', function () {
register_post_type('testimonial', [
'label' => __('Testimonials', 'mytheme'),
'public' => true,
'show_in_rest' => true,
'supports' => ['title'], // no 'editor' — fields-only
]);
if (function_exists('gcblite_register_post_fields')) {
gcblite_register_post_fields('testimonial', [
'controls' => [
['type' => 'textarea',
'attributeKey' => 'quote',
'label' => __('Quote', 'mytheme'),
'validation' => ['required' => true, 'minLength' => 10]],
['type' => 'text',
'attributeKey' => 'author_name',
'label' => __('Author name', 'mytheme'),
'validation' => ['required' => true]],
['type' => 'image',
'attributeKey' => 'author_image',
'label' => __('Author headshot', 'mytheme')],
],
]);
}
});What the author sees
Visit any post of this CPT — you'll see a Fields meta-box with the controls you declared. The block editor body is stripped by default (the record IS the data, not a wrapped document). Opt back in by passing has_body => true.
REST exposure
Every field is automatically registered as REST meta with its typed schema. You can read it via:
curl "https://example.com/wp-json/wp/v2/testimonial?per_page=10&_embed=1"Response:
[
{
"id": 42,
"title": { "rendered": "Maya Hernández" },
"meta": {
"quote": "The editor preview and the live site are the same component...",
"author_name": "Maya Hernández",
"author_image": {
"url": "https://example.com/wp-content/uploads/.../maya.jpg",
"alt": "Maya Hernández",
"width": 200,
"height":200
}
}
}
]
gcblite_register_post_fieldsautomatically enablescustom-fieldssupport on the CPT — without that, WP core suppressesmetafrom REST responses even for registered fields. You don't need to add it to yoursupportsarray.
Config keys
controls
Required. Same shape as a block's block.fields.json controls array. See the Field reference.
has_body
Optional (default false). When true, keeps the block editor body on the post-edit screen alongside the fields meta-box. Use this when the CPT really is a hybrid — record data PLUS a free-form body (e.g. a project with structured metadata and a long case-study).
Consume
JSX
import { getCptCollection } from '@/lib/wpRestClient';
export default async function Testimonials({ attributes }) {
const items = await getCptCollection('testimonial', attributes);
return items.map((t) => (
<blockquote key={t.id}>
<p>{t.meta.quote}</p>
<cite>{t.meta.author_name}</cite>
</blockquote>
));
}PHP
<?php
use GCBLite\Collection;
$items = Collection::query('testimonial', $attributes);
foreach ($items as $t):
$quote = get_post_meta($t->ID, 'quote', true);
$author = get_post_meta($t->ID, 'author_name', true);
?>
<blockquote>
<p><?php echo esc_html($quote); ?></p>
<cite><?php echo esc_html($author); ?></cite>
</blockquote>
<?php endforeach; ?>The
attrsargument is the section block's own attribute set. The helper readssource("latest" / "manual"),count, andpost_idsfrom it — so a single helper covers both query modes.
From the authoring guide
Post-fields: gcb-lite controls on a custom post type
Themes (or other plugins) can attach the gcb-lite control library to any
CPT to render a meta-box of typed fields, REST-exposed via meta:
register_post_type('testimonial', [
'label' => 'Testimonials',
'public' => true,
'show_in_rest' => true,
'supports' => ['title'], // 'editor' is auto-stripped when fields are registered
]);
gcblite_register_post_fields('testimonial', [
// 'has_body' => true, // opt back in to the block editor body
'controls' => [ /* same shape as block.fields.json */ ],
]);- The same control library (text, image, gallery, color, post-object, …) used in block Inspectors renders inside a classic add_meta_box.
- Each field becomes
meta.{attributeKey}on the CPT's REST endpoint (/wp/v2/{post_type}?_fields=id,title,meta), suitable for a headless React frontend. - By default the block editor body is removed (record-style CPTs don't
need a content body). Pass
'has_body' => trueto keep it. validation+conditionalLogicwork here exactly as in blocks.