admin管理员组文章数量:1405894
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:
/
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?
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?
Share Improve this question edited Dec 4, 2019 at 5:45 Denoteone asked Dec 4, 2019 at 2:37 DenoteoneDenoteone 2091 gold badge4 silver badges12 bronze badges1 Answer
Reset to default 0You 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
]);
本文标签: metaboxOptions to get my custom post type metadata via the WordPress API
版权声明:本文标题:metabox - Options to get my custom post type metadata via the WordPress API 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744941977a2633542.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论