Skip Navigation

[Resolved] Automatically adding custom fields to REST API

This thread is resolved. Here is a description of the problem and solution.

Problem:

Once I set up the Custom Post Type to be exposed via the REST API I expect the associated Post Field Group fields to be exposed as well

Solution:

The client have been found a workaround with another plugin "WP REST API Controller":

https://wordpress.org/plugins/wp-rest-api-controller/

Relevant Documentation:

This support ticket is created 6 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 5 replies, has 3 voices.

Last updated by chrisH-10 6 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#923817

Tell us what you are trying to do?
Once I set up the Custom Post Type to be exposed via the REST API I expect the associated Post Field Group fields to be exposed as well, but they are not.
I have been creating a custom plugin to expose fields as I add them, but this tedious.
(a) are you working on a solution for this?
(b) I'm happy to write a more generic plugin, but I didn't have any luck finding a function in the Codex for getting all the fields of a Custom Post Type. Clearly you know how to do this. Could you enlighten me or provide a snippet?

Is there any documentation that you are following?
No, could not find any.

#923943

Hello,

You are right, there isn't such a built-in feature within Types plugin, and it has been reported lots of time, for example:
https://toolset.com/forums/topic/rest-api-update-custom-fields/
https://toolset.com/forums/topic/exposing-custom-fields-through-rest-api/
https://toolset.com/forums/topic/how-to-get-custom-fields-into-the-rest-api-output/

We hope to include support for these in a future release, but I don't have an ETA for you right now. if you agree, we can mark this thread as a feature request, and let our team know it's important for you!

#923947
#924054

Thanks Luo, stellar support as always!

That stackexchange article has a link to https://wordpress.org/plugins/wp-rest-api-controller/ which appears to be the plugin I was looking to create, how awesome!

The other support links you provided were old, closed and contain many a "hidden link", so I figured I'd ask again. There seem to have been a lot of requests for this. For my needs the REST API Controller plugin does what I need. You may want to evaluate that and perhaps endorse/contribute to it.

If you do build this into Types I would expect to see a checkbox on the field create/edit UI where I can check a box to add it to REST. I would also hope for a PHP filter so I can transform the output for the field.

Thanks!

#1169566

what's on the hidden link?
how to update custom fields using rest api?

#1169800

I think it was a link to a Stack Exchange article. What you want is the plugin I referenced. It's actively maintained and allows you to add your custom fields to the REST API with a UI.

https://wordpress.org/plugins/wp-rest-api-controller/