0

I'm doing my site with two pieces -- the headless CMS on a subdomain where content is entered, and the root domain where I display data. Only WP is installed in the subdomain, not the root domain. In the subdomain, I created a custom post type called Staff, and then items inside are a Member. I noticed that I can't use the URL...

https://example.com/wp-json/wp/v2/posts

(WP REST API)

...to read these items. Looking in the docs, I see that I can address it as...

https://example.com/wp-json/wp/v2/staff

When I use /staff, it shows me the core post fields, but not any of the custom field groups. (Note, I'm using the Custom Post Types plugin from TotalPress.org.)

How do I get a given staff member's custom field properties on their record? I can access someone such as:

https://example.com/wp-json/wp/v2/staff/?slug=john-smith

...but there are no custom fields in there that I attached to this record.

How do I use the REST API to get the custom fields attached to a custom post type?

5
  • have you declared that they're available via rest api when registering? There is no code in your question
    – Tom J Nowell
    Commented Sep 13, 2021 at 0:39
  • @TomJNowell I'm using the Custom Post Types plugin from TotalPress.org, which saves me the coding. It is doing the registering. I also figured out why the /staff wasn't working in the API -- it was how I declared it. I'll be editing this post on that part, at least. I just can't get the custom fields.
    – Volomike
    Commented Sep 13, 2021 at 1:14
  • I thought you had used it then abandoned it based on your question. 3rd party plugin support is off topic here. This is not a place to get help with the Custom Post Types plugin.
    – Tom J Nowell
    Commented Sep 13, 2021 at 9:16
  • Of note, the canonical answer to this is to ensure permalinks are flushed and the CPT in question has show_in_rest set to true, but because you used a plugin to build your post types that solution is unavailable to you. Having said that, custom post types are straight forward and there are code generators online that write the code for you based on inputs and checkboxes. You don't need a plugin to auto-register post types for you
    – Tom J Nowell
    Commented Sep 13, 2021 at 9:18
  • And you have to register meta to have it show up in the REST API
    – Tom J Nowell
    Commented Sep 13, 2021 at 9:19

1 Answer 1

0

I found the fix without code. I installed the Rest API Helper Plugin and it now exposed the custom fields on a given post type.

3
  • 1
    interesting definition of "without code", maybe you ment "without writting any code by myself" :) Commented Sep 13, 2021 at 5:17
  • just be aware that the plugin doesn't seem to be maintained. might still work properly for a long time but you are taking a risk Commented Sep 13, 2021 at 5:20
  • @MarkKaplun 'without code I did by myself' -- yes, you are correct there. And thanks for the other advice.
    – Volomike
    Commented Sep 16, 2021 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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