Rest API Post to Custom Tables not work
Support › MB REST API › Rest API Post to Custom Tables not workResolved
- This topic has 12 replies, 6 voices, and was last updated 2 years ago by
[email protected].
-
AuthorPosts
-
June 12, 2019 at 9:12 PM #14946
[email protected]
ParticipantHello, 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
June 13, 2019 at 11:16 AM #14956Anh Tran
KeymasterHi, 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?
June 14, 2019 at 12:54 AM #14960[email protected]
ParticipantThank you. I try it and now works fine. Great plugin.
June 14, 2019 at 3:46 PM #14964[email protected]
Participant- URGENT IMPORTANT -
Hello, after applied the fix, posts works fine (GET and POST) but Now custom user fields used in profile are not display in json (even get or to post).
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": [
...June 20, 2019 at 4:09 PM #15019Anh Tran
KeymasterHi,
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.
June 22, 2019 at 11:08 AM #15046Anh Tran
KeymasterAfter checking the code, I found that the fix actually works. Can you please try again?
June 27, 2019 at 4:17 PM #15136[email protected]
ParticipantHello, 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-APIAt 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 systemApril 19, 2021 at 4:03 PM #27374[email protected]
ParticipantHey,
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.
MaikNovember 29, 2021 at 4:09 PM #32254A Rollin
ParticipantCan we get some help here?
March 22, 2023 at 8:29 PM #41169[email protected]
ParticipantI 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
ThanksMarch 24, 2023 at 2:07 AM #41191Shalom Pennington
ParticipantYes, 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.
March 24, 2023 at 2:27 AM #41193[email protected]
ParticipantVia 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.April 7, 2023 at 11:13 PM #41389[email protected]
ParticipantThe latest update still has not fixed this issue 🙂
- URGENT IMPORTANT -
-
AuthorPosts
- You must be logged in to reply to this topic.