API Rest field integration
ACPT comes with a custom integration with the standard WordPress API Rest.
Read operations
Suppose you have registered a custom meta field called text
for native posts.
Call the endpoint:
/wp-json/wp/v2/posts
Inside the post objects, you’ll find the node called acpt
:
{
"id":2274,
"date":"2022-02-22T12:46:10",
"date_gmt":"2022-02-22T12:46:10",
"guid":{
"rendered":"http://localhost:83/?p=2274"
},
"modified":"2022-02-22T13:00:09",
"modified_gmt":"2022-02-22T13:00:09",
"slug":"ciao",
"status":"publish",
"type":"post",
"link":"http://localhost:83/ciao/",
"title":{
"rendered":"Ciao"
},
"content":{
"rendered":"\n<p>lorem ispum</p>\n",
"protected":false
},
"excerpt":{
"rendered":"<p>lorem ispum</p>\n",
"protected":false
},
"author":1,
"featured_media":0,
"comment_status":"open",
"ping_status":"open",
"sticky":false,
"template":"",
"format":"standard",
"meta":[
],
"category":[
47
],
"post_tag":[
],
"other":[
],
"acpt":{
"meta":[
{
"meta_box":"info",
"meta_fields":[
{
"name":"text",
"type":"Text",
"options":[
],
"value":"",
"default":"",
"required":false,
"showInAdmin":false
}
]
}
]
},
"_links":{}
}
If you have installed WooCommerce try to call:
/wp-json/wp/v2/product
in this case the acpt
object contains also a key called wc_product_data
, an array of meta fields objects:
[
{
"id": 2003,
"date": "2022-01-21T14:50:29",
"date_gmt": "2022-01-21T14:50:29",
"guid": {
"rendered": "http://localhost:83/?post_type=product&p=2003"
},
"modified": "2022-02-23T11:28:30",
"modified_gmt": "2022-02-23T11:28:30",
"slug": "nuovo-prodotto",
"status": "publish",
"type": "product",
"link": "http://localhost:83/product/nuovo-prodotto/",
"title": {
"rendered": "Nuovo prodotto"
},
"content": {
"rendered": "<p>um has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.um has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.um has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>\n",
"protected": false
},
"excerpt": {
"rendered": "<p>um has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of […]</p>\n",
"protected": false
},
"featured_media": 1142,
"comment_status": "open",
"ping_status": "closed",
"template": "",
"meta": [],
"product_cat": [
16
],
"product_tag": [],
"acpt": {
"meta": [],
"wc_product_data": [
{
"name": "Product data",
"icon": {
"icon": "storefront",
"value": "\\e900"
},
"visibility": [
"show_if_simple",
"show_if_variable",
"show_if_grouped",
"show_if_external"
],
"fields": [
{
"name": "field",
"type": "Text",
"options": [],
"value": "",
"default": "",
"required": false
}
]
}
]
},
"_links": {
"self": [
{
"href": "http://localhost:83/wp-json/wp/v2/product/2003"
}
],
"collection": [
{
"href": "http://localhost:83/wp-json/wp/v2/product"
}
],
"about": [
{
"href": "http://localhost:83/wp-json/wp/v2/types/product"
}
],
"replies": [
{
"embeddable": true,
"href": "http://localhost:83/wp-json/wp/v2/comments?post=2003"
}
],
"wp:featuredmedia": [
{
"embeddable": true,
"href": "http://localhost:83/wp-json/wp/v2/media/1142"
}
],
"wp:attachment": [
{
"href": "http://localhost:83/wp-json/wp/v2/media?parent=2003"
}
],
"wp:term": [
{
"taxonomy": "product_cat",
"embeddable": true,
"href": "http://localhost:83/wp-json/wp/v2/product_cat?post=2003"
},
{
"taxonomy": "product_tag",
"embeddable": true,
"href": "http://localhost:83/wp-json/wp/v2/product_tag?post=2003"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
{
"id": 35,
"date": "2020-06-03T16:42:23",
"date_gmt": "2020-06-03T16:42:23",
"guid": {
"rendered": "http://localhost:83/?post_type=product&p=35"
},
"modified": "2022-01-21T14:56:08",
"modified_gmt": "2022-01-21T14:56:08",
"slug": "prodotto-bello",
"status": "publish",
"type": "product",
"link": "http://localhost:83/product/prodotto-bello/",
"title": {
"rendered": "Prodotto bello"
},
"content": {
"rendered": "<p>Lorem ipsum</p>\n",
"protected": false
},
"excerpt": {
"rendered": "<p>Lorem ipsum</p>\n",
"protected": false
},
"featured_media": 0,
"comment_status": "open",
"ping_status": "closed",
"template": "",
"meta": [],
"product_cat": [
16
],
"product_tag": [],
"acpt": {
"meta": [],
"wc_product_data": [
{
"name": "Product data",
"icon": {
"icon": "storefront",
"value": "\\e900"
},
"visibility": [
"show_if_simple",
"show_if_variable",
"show_if_grouped",
"show_if_external"
],
"fields": [
{
"name": "field",
"type": "Text",
"options": [],
"value": "",
"default": "",
"required": false
}
]
}
]
},
"_links": {
"self": [
{
"href": "http://localhost:83/wp-json/wp/v2/product/35"
}
],
"collection": [
{
"href": "http://localhost:83/wp-json/wp/v2/product"
}
],
"about": [
{
"href": "http://localhost:83/wp-json/wp/v2/types/product"
}
],
"replies": [
{
"embeddable": true,
"href": "http://localhost:83/wp-json/wp/v2/comments?post=35"
}
],
"wp:attachment": [
{
"href": "http://localhost:83/wp-json/wp/v2/media?parent=35"
}
],
"wp:term": [
{
"taxonomy": "product_cat",
"embeddable": true,
"href": "http://localhost:83/wp-json/wp/v2/product_cat?post=35"
},
{
"taxonomy": "product_tag",
"embeddable": true,
"href": "http://localhost:83/wp-json/wp/v2/product_tag?post=35"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
}
]
Write operations
In order to write meta fields data via API, make a POST request to the same endpoint:
/wp-json/wp/v2/posts
You have to add acpt
node to the usual JSON payload.
Suppose you want to create a new post with the title “Lorem ipsum”:
{
"title": "Lorem ipsum",
"acpt": {
"meta": [
{
"box": "info",
"field": "text",
"value": "This is the value"
}
]
}
}
Please note that some fields require the value to be an array.
Suppose you have a select multiple type field called “select” within “info” meta box:
{
"title": "Lorem ipsum",
"acpt": {
"meta": [
{
"box": "info",
"field": "select",
"value": [
"This is the value",
"This is another value",
"This is the third value",
]
}
]
}
}