Test365i
365i.co.uk
Back to all guides
Plugin

Create a JetEngine post type over the REST API

A JetEngine post type can be created without opening WP admin, by sending JetEngine the same requests its own settings screen sends. The guide collection on this site was built that way in three calls. This guide shows each request, and the one setting that makes the custom fields show up in the REST API.

20 minutesJetEngine

Works on WordPress 7.2, JetEngine 3.9.1.3; application passwords need WordPress 5.6 or later

Editorial integrity: read our editorial standards.

  1. Create an application password and test it

    In WP admin, open Users > Profile, scroll to Application Passwords, give it a name and copy the password it shows. It only works for the REST API and can be revoked on its own, so a script never needs your real login.

    This first request proves it works: it asks WordPress who you are. If your name comes back, every later request will be authorised. Keep the password out of files you share; these examples use shell variables.

    Five REST requests: check access, add a post type, add a taxonomy, create an entry and read it back
    The whole job is five requests, all signed with one application password.
    auth-check.shShell
    # WP admin > Users > Profile > Application Passwords: add one, then test it.
    SITE="https://www.your-site.example"
    AUTH="admin:abcd efgh ijkl mnop qrst uvwx"
    curl -s -u "$AUTH" "$SITE/wp-json/wp/v2/users/me?context=edit" | grep -o '"name":"[^"]*"'
  2. Describe the post type and its fields in JSON

    This is the shape JetEngine's post type screen saves: general settings, labels, advanced settings and a list of meta fields. show_in_rest appears twice on purpose. On the post type it puts the entries in the REST API; on each field it puts that field's value there too.

    The post type and each meta field both set show_in_rest to true
    show_in_rest is set twice: once for the entries, once per field.
    post-type.jsonJSON
    {
    	"general_settings": { "name": "Guides", "slug": "guide" },
    	"labels": { "name": "Guides", "singular_name": "Guide", "menu_name": "Guides" },
    	"advanced_settings": {
    		"public": true,
    		"show_in_rest": true,
    		"has_archive": true,
    		"rewrite_slug": "guides",
    		"supports": ["title", "editor", "excerpt", "thumbnail", "elementor"]
    	},
    	"meta_fields": [
    		{ "title": "Time needed", "name": "time_needed", "object_type": "field", "type": "text", "show_in_rest": true, "rest_api": true },
    		{ "title": "Works on", "name": "versions", "object_type": "field", "type": "text", "show_in_rest": true, "rest_api": true }
    	]
    }

    The WordPress REST API handbook, in the page written by James Nylen, says what happens to fields that are not registered properly:

    Otherwise the meta fields will not appear in the REST API.

    James Nylen, WordPress REST API Handbook, "Modifying Responses"

    JetEngine registers the meta for you, but it only exposes a field to the REST API when that field's own show_in_rest is on. The post type setting is not enough on its own, which is why the JSON in this step sets both.

  3. Send it to JetEngine to create the post type

    /jet-engine/v2/add-post-type is the route JetEngine's own admin screen uses, so it needs an administrator. A successful reply includes "success":true and the new item's ID. JetEngine also has get-post-type and edit-post-type routes for later changes; to edit, read the item first and send back the whole definition with your change, so nothing is dropped.

    A POST to the add-post-type route returns success true, and later changes use get-post-type and edit-post-type
    One request creates the post type.
    create-post-type.shShell
    curl -s -u "$AUTH" -H "Content-Type: application/json" \
    	--data @post-type.json \
    	"$SITE/wp-json/jet-engine/v2/add-post-type"
  4. Add a taxonomy for the new post type

    Taxonomies follow the same pattern with add-taxonomy. object_type attaches it to the post type, and the rewrite slug sets its address. On this site the same call made the Topic and the "What you need" filters you can see on the Lab guide list.

    A POST to add-taxonomy attaches Topics to Guides, with term archives under guides/topic
    The taxonomy follows the same pattern as the post type.
    create-taxonomy.shShell
    curl -s -u "$AUTH" -H "Content-Type: application/json" \
    	--data '{
    		"general_settings": { "name": "Topics", "slug": "guide-topic", "object_type": ["guide"] },
    		"labels": { "name": "Topics", "singular_name": "Topic" },
    		"advanced_settings": { "public": true, "show_in_rest": true, "hierarchical": true, "rewrite_slug": "guides/topic" }
    	}' \
    	"$SITE/wp-json/jet-engine/v2/add-taxonomy"

    The register_post_type reference describes the post type setting in six words:

    Whether to include the post type in the REST API.

    WordPress Developer Resources, register_post_type() reference

    JetEngine passes its show_in_rest setting straight to that argument. Turning it on gives the post type its own /wp/v2/ route, which is what steps 5 and 6 use, and it is also what lets the block editor and Elementor's dynamic tags read the entries.

  5. Create an entry with its custom fields

    Entries go through the standard WordPress route for the post type, /wp/v2/guide here, with the field values under meta. Send every value as a string, even for a JetEngine number field: when I sent a height as a number, WordPress answered 400 ("is not of type string") but still created the post, which left a duplicate to clean up.

    String meta values return 201 Created; a number returned 400 but still created a duplicate post
    Send a number and WordPress answers 400, yet the post is still created.
    create-entry.shShell
    curl -s -u "$AUTH" -H "Content-Type: application/json" \
    	--data '{ "title": "My first guide", "status": "draft", "meta": { "time_needed": "15 minutes", "versions": "WordPress 7.2" } }' \
    	"$SITE/wp-json/wp/v2/guide"
  6. Read the entry back and check the meta

    context=edit returns the stored values. If meta comes back empty, the field is missing show_in_rest: that was exactly what happened when this site's collection was first built, and setting it on each field fixed it at once. Every guide in the Elementor 4 element gallery's collection loop reads these fields.

    A context=edit request returns the stored meta, or empty meta when a field lacks show_in_rest
    Empty meta means a field is missing show_in_rest.
    read-back.shShell
    curl -s -u "$AUTH" "$SITE/wp-json/wp/v2/guide?status=draft&context=edit" | grep -o '"meta":{[^}]*}'

What creating a JetEngine post type over REST does not do

The /jet-engine/v2/ routes are the ones JetEngine's admin screens use, not a documented public API, so a JetEngine update could change them. Read an item back before you edit it.

Some JetEngine features did not persist when saved this way on this site: a Query Builder query created over REST did not stay saved, so queries were set up in the editor instead.

It does not enable Elementor for the post type. Tick the post type under Elementor > Settings > Post Types, or Elementor content on its entries is discarded when you publish.

All the JetEngine post type REST code

Each file below is complete. Copy it, or download it under the name shown.

auth-check.shShell
# WP admin > Users > Profile > Application Passwords: add one, then test it.
SITE="https://www.your-site.example"
AUTH="admin:abcd efgh ijkl mnop qrst uvwx"
curl -s -u "$AUTH" "$SITE/wp-json/wp/v2/users/me?context=edit" | grep -o '"name":"[^"]*"'
post-type.jsonJSON
{
	"general_settings": { "name": "Guides", "slug": "guide" },
	"labels": { "name": "Guides", "singular_name": "Guide", "menu_name": "Guides" },
	"advanced_settings": {
		"public": true,
		"show_in_rest": true,
		"has_archive": true,
		"rewrite_slug": "guides",
		"supports": ["title", "editor", "excerpt", "thumbnail", "elementor"]
	},
	"meta_fields": [
		{ "title": "Time needed", "name": "time_needed", "object_type": "field", "type": "text", "show_in_rest": true, "rest_api": true },
		{ "title": "Works on", "name": "versions", "object_type": "field", "type": "text", "show_in_rest": true, "rest_api": true }
	]
}
create-post-type.shShell
curl -s -u "$AUTH" -H "Content-Type: application/json" \
	--data @post-type.json \
	"$SITE/wp-json/jet-engine/v2/add-post-type"
create-taxonomy.shShell
curl -s -u "$AUTH" -H "Content-Type: application/json" \
	--data '{
		"general_settings": { "name": "Topics", "slug": "guide-topic", "object_type": ["guide"] },
		"labels": { "name": "Topics", "singular_name": "Topic" },
		"advanced_settings": { "public": true, "show_in_rest": true, "hierarchical": true, "rewrite_slug": "guides/topic" }
	}' \
	"$SITE/wp-json/jet-engine/v2/add-taxonomy"
create-entry.shShell
curl -s -u "$AUTH" -H "Content-Type: application/json" \
	--data '{ "title": "My first guide", "status": "draft", "meta": { "time_needed": "15 minutes", "versions": "WordPress 7.2" } }' \
	"$SITE/wp-json/wp/v2/guide"
read-back.shShell
curl -s -u "$AUTH" "$SITE/wp-json/wp/v2/guide?status=draft&context=edit" | grep -o '"meta":{[^}]*}'

JetEngine post type over REST questions

Can I create a JetEngine post type without WP admin?

Yes. Send JetEngine the same requests its settings screen sends, authenticated with an application password belonging to an administrator.

Why are my JetEngine fields missing from the REST API?

Each field needs show_in_rest switched on. The post type setting alone does not expose field values.

Is an application password safe to use in scripts?

It only works for the REST API, has its own name and can be revoked without changing your login. Keep it out of shared files.

Can I edit the post type later the same way?

Yes, with get-post-type and edit-post-type. Read the item first and send back the full definition with your change.

Why did my entry save but the meta did not?

A value did not match what the REST API expects, for example a number where JetEngine registered the field as a string. WordPress rejects the request with a 400 but can still create the post.

Do I need JetEngine for this?

For these routes, yes. Without JetEngine, register_post_type() and register_meta() in a small plugin do the same job.

Will Elementor work on the new post type?

Only after you tick it in Elementor > Settings > Post Types.

Sources

  1. WordPress REST API Handbook: Modifying Responses
  2. WordPress Developer Resources: register_post_type()
  3. Crocoblock: JetEngine knowledge base

More build guides

The latest guides, newest first.

Elementor

A clickable card grid with the Elementor 4 Collection loop

The Elementor 4 Collection loop repeats one design for every post a query finds. On this site it lists the build guides, which are a JetEngine post type, in the element gallery, the Lab and the mega menu, all from one card component. This guide builds that grid, makes each whole card clickable and hides fields that come back empty.

25 minutes Get the guide
Elementor

Style the Elementor 4 Carousel element: arrows, dots and loop

The Elementor 4 Carousel element gives you slides, arrows and dots as separate atomic parts. Out of the box on this site, the arrows sat on top of the slide titles, the active dot was black on a dark panel and Loop did nothing. This guide fixes all three, with the CSS the element gallery now runs.

20 minutes Get the guide
Elementor

The Elementor 4 Accordion element, built on native details

The Elementor 4 Accordion element is built on the browser's own details and summary elements, so it opens and closes with no script. This guide sets it up the way the element gallery on this site does, styles it with classes, and explains the FAQ schema switch and what Google now does with it.

15 minutes Get the guide