Skip Navigation

[Closed] Expose intermediary post-type custom fields to API

This support ticket is created 2 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.

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 2 years, 4 months ago.

Author
Posts
#2442515

Hi

i would like to query an intermediary post-type and its custom fields via the REST API. after activating the option show_in_rest on the post-type, it can be listed. but the custom fields are not being printed. i've activated the option via " Go to the Toolset -> Settings page and on Custom Content tab enable the REST API option. ", it's working correctly on all other 'normal' post-types, but not on the intermediary post-type.

is there anything that can be done about it?

Thanks!

#2442619

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

I just did some preliminary checks on my own test site, and I see that—yes—when you query the intermediate post type via the REST API the "toolset-meta" property is missing in the returned JSON result, even when you enable the REST API for the post type, and enable the REST API in the Toolset settings.

Ordinarily I would say the way to get round this limitation would be to use the native meta property that WordPress returns. That has the raw post meta values (the toolset-meta property contains pre-formatted results, but the raw values may be sufficient.

To enable that you need to make sure that the custom post type setting has support for custom fields enabled (in the Toolset settings page for the post type that would mean enabling custom fields in the section "Sections to display when editing...".)

But it could be that you would need to register the custom fields (recalling that Toolset fields are stored with a key prefix of 'wpcf-') using register_meta first for them to be included in the result. (I didn't set up a complete test, so keep an eye on that.)

https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/#working-with-registered-meta-in-the-rest-api
https://developer.wordpress.org/reference/functions/register_meta/

The topic ‘[Closed] Expose intermediary post-type custom fields to API’ is closed to new replies.