Support Forum
Support › MB REST API › Rest API Post to Custom Tables not workResolved
Hello, I have serveral custom post-types with custom fields storing data to custom tables.
Each custom post-type as is set of fields storing data to custom tables.
Using rest API to get data by json works fine:
Example:
[
{
"id": 582,
"date": "2019-06-12T10:34:17",
"date_gmt": "2019-06-12T10:34:17",
"modified": "2019-06-12T12:49:47",
"modified_gmt": "2019-06-12T12:49:47",
"slug": "morada-2-4",
"status": "publish",
"type": "morada",
"title": {
"rendered": "Morada 2"
},
"parent": 0,
"template": "",
"meta_box": {
"campo1": "",
"campo2": ""
},
...
PROBLEM 1:
Using POST not working to create or update the meta_box fields:
{
"meta_box": {
"campo1": "some_data1",
"campo2": "some_data2"
}
Wp fields as title ou slug updates is information (stored in wp default database), but the fields "campo1" and "campo2" who stores is data in custom table not update.
All my sistem is based in custom post-types and custom metabox fields and all post creation ou updates need to be done by json (GET and POST).
Using custom tables increase organization and loading speed.
Can you please check? Thanks
Hi, I've just tested the plugin and it works fine to me. Here is the video I made for that:
Update 1: I replied too fast. I didn't notice you were talking about custom table. Let me check that again.
Update 2: I've just pushed a fix to the plugin here. Can you please try it?
Thank you. I try it and now works fine. Great plugin.
BEFORE
"id": 4,
...
"meta_box": {
"address": "Street 123",
"postcode": "4321-123",
"region": "Some",
"state": "Some",
"tel": "121212121",
"lat": "-8.000001",
"lon": "45.000001",
"other": "some info"
},
NOW
...
"meta_box": null,
"_links": {
"self": [
...
Hi,
I've just tried it with MB User Meta and it works fine. However, I think the fix above doesn't work well for updating users. I'll probably need to find a better fix.
After checking the code, I found that the fix actually works. Can you please try again?
Hello, the metabox system is not working in the following situation:
A data management system based on CUSTOM TABLES was developed for the registration of information, for various reasons, the main one being the organization and speed of data queries.
The system was created to work with an app, aiming to send and receive data by Rest-API
At the data level it only uses CUSTOM POST-TYPES, it does not use wordpress post-types.
Uses CUSTOM TABLES for USER PROFILE data logging of post-types and data logging.
Problem with user profile data
It is working correctly via WordPress Back-office. If you create or edit the profile data in Backoffice, you record and change the data added or changed in the table correctly.
Does not work in the REST API on profile data refresh.
GET correctly queries data from the defined table (collects data)
POST does not change the data. When you run a post it does not give an error and displays the data as changed but does not record it in the created table.
GET Example
{
"id": 4,
"name": "Manuel",
"url": "",
"description": "",
"link": "https:\/\/resn.arsites.eu\/arquivo\/author\/agro",
"slug": "agro",
"meta": [],
"meta_box": {
"address": "Frango assado",
"postcode": "4512-568",
"region": "Nogueiró",
"state": "Braga",
"tel": "253123456",
"lat": "-8.56885555",
"lon": "45.5898989",
"other": "Nada a informar"
},
"_links": {
"self": [
{
"href": "https:\/\/resn.arsites.eu\/wp-json\/wp\/v2\/users\/4"
}
],
"collection": [
{
"href": "https:\/\/resn.arsites.eu\/wp-json\/wp\/v2\/users"
}
]
}
}
POST Example
"meta_box": {
"address": "Rua das Casas 12666",
"postcode": "4512-568",
"region": "Nogueiró",
"state": "Braga",
"tel": "253123456",
"lat": "-8.56885555",
"lon": "45.5898989",
"other": "Nada a informar agora"
},
Example GET after POST (nothing change)
"meta_box": {
"address": "Frango assado",
"postcode": "4512-568",
"region": "Nogueiró",
"state": "Braga",
"tel": "253123456",
"lat": "-8.56885555",
"lon": "45.5898989",
"other": "Nada a informar"
},
The example user's address is https://resn.arsites.eu/wp-json/wp/v2/users/4
If you wish I can indicate an access to the system
Hey,
i just wanted to store user meta_fields in an custom table
and access (Create & Update) it with the Rest API.
And i did not work. When storing the data inside the postmeta table, it works.
I found this thread with the same problem.
Is this expected behavior?
Thanks in advance.
Maik
Can we get some help here?
I could save datas to Custom Table via API calls on Metabox 5.6.4 + Metabox AIO 1.16.2 (and older versions)
But after updating MB plugins. The API runs normally but It no longer saved to Custom Table any more
Did Anyone get that problem?
I must keep old version and stop updating MB long time ago to keep everything work via API
Thanks
Yes, having the same problem, but relatively new to MB so haven't ever upgraded. Posting with Postman shows updated info in the response, but updates aren't written to DB when using REST.
Original value:
{
"meta_box": {
"file_key": "123123",
"file_name": "Basement"
}
}
What I'm posting to CPT endpoint: domain.local/wp-json/wp/v2/cpt_slug/428
{
"meta_box": {
"file_key": "123123",
"file_name": "Basement NEW"
}
}
What POST response shows: (abbreviated for clarity)
{
"meta_box": {
"file_key": "123123",
"file_name": "Basement NEW"
}
}
What a GET request to same endpoint shows (domain.local/wp-json/wp/v2/cpt_slug/428)
{
"meta_box": {
"file_key": "123123",
"file_name": "Basement"
}
}
Changes aren't being stored when using custom table. If I switch to just using default storage these EXACT same REST calls work exactly as expected. This is causing all kinds of heartburn. Is this a bug or is there some other setting that needs to be set? Making changes through WP admin works fine and data is written to custom table just fine. Problem is my use case relies HEAVILY on REST.
Via API Calls, all the custom post data are saved somewhere, not in post meta table or custom post table.
You can see the post with all data on the admin page. and then all data will disappear.
The latest update still has not fixed this issue 🙂