Serve The Base is a WordPress parent theme that allows for rapid and highly-customized REST API creation. It parses a JSON file in your child theme and generates all of your custom post types, taxonomies, and meta fields for you.
STB is designed to be completely front-end agnostic. You can build a full front-end in your child theme, or you can use your WordPress site as the backend for a fully decoupled CMS.
STB will register all custom post types, taxonomies, and fields specified in the schema file. It will create all necessary REST endpoint as well as include data from your custom fields as part of responses.
STB makes absolutely no decisions about the front-end of your site. If you try using STB as a parent theme, it will yell at you.
- Download a zip of the theme and install it like normal
cd
to the theme directory and runcomposer install
β this assumes you have composer itself installed- Make a new directory in your theme directory β this will be your child theme. In this theme, create two files:
functions.php
andstyle.css
. In style.css add the following:
/*
Theme Name: <your theme name>
Template: <directory where STB installed>
*/
- Create a file named
schema.json
in your child theme. You can start with the contents ofschema-sample.json
in this repo, or start from scratch
A sample schema.json
file is provided with this project that can be used as a reference. Your file should look something like this:
{
"types": [
{
"name": string | required
"plural": string | optional β provide only for non-standard pluralizations (e.g. "radii", "children")
"supports": array<string> | optional β used as "supports" argument when registering CPT
"args": object | optional β non-default args to be used when registering CPT
}
],
"taxonomies: [
{
"name": string | required
"plural": string | optional β provide for non-standard pluralizations
"describes": array<string>|string | optional β post type(s) that the taxonomy will be associated with. default "post"
"args": object | optional βΒ non-default args to be used when registering custom taxonomy
}
],
"field_groups: [
{
"name": string | required
"belongs_to": array<string>|string|"all" β post type(s) that the field group will belong to. default "post"
"fields": { array<object> | required
{
"name": string | required
"type": string | optional β defaults to "text_small"
"options": array<string> | optional
}
}
}
]
}
Referring to the documentation for registering custom post types, custom taxonomies, and CMB2 fields may be helpful.
This project is in a production-ready state, but I'll keep it maintained should anything in WordPress core or in CMB2 change. If anyone wants to put together a fork which works with ACF, go for it!
This project wouldn't be possible without CMB2.