2

I am using a plugin that adds multiple custom post types all of which have their own meta-data. I am able to expose the custom post type to WordPress's API but the metadata collected with those post is not.

For example "Team Members" is a post type and it is declared in the team.php file. I was able to add it to the WP API via 'show_in_rest' => true, there is also a team-metaboxes.php which I tried to add the same attribute to by am not seeing it in the API JSON.

I am seeing the team metadata in the wp_postmeta table in the DB but I am having a hard time accessing it via the API.

What are my options. As of now I am using:

http://cmyk-demo.ra/wp-json/wp/v2/team-post/

But am not sure how to get the metadata for the team-post content types.

Per a recommendation below I have added the following snippet to my themes functions.php and still no meta data in the JSON returned from the API:

register_meta('post', 'fb_si', [
    'object_subtype' => 'team-post',
    'show_in_rest' => true
]);

The fact that the metaboxes are added via a plugin would that matter?

0

You should use register_meta to add the meta field to the rest controller. Here the example from the link to expose the field my_meta of the custom post type my_article:

register_meta('post', 'my_meta', [
  'object_subtype' => 'my_article',
  'show_in_rest' => true
]);
2
  • See my edit above regarding the snippet of code I added to my functions.php found in my themes root. I am not seeing the fb_si field in my JSON. Am I missing something?
    – Denoteone
    Dec 4 '19 at 5:43
  • Yeah it could be an issue depending on where the plugin is really storing the data. Are you sure is stored in post_meta? Dec 4 '19 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.