I’ve been banging my head against a custom post type and advanced custom fields problem for quite a while now and I’m out of ideas. Long story short, I’m relatively new to Wordpress and I’m creating some custom crud endpoints in order to build my clients website.
Here’s the thing. My URL is ‘http://dummydatathroughfakeapiwp.local/wp-json/api/v1/events/95’. I’ve setup the custom post type 'event' using CPT UI. I’ve enabled the flag for showing it in the REST api (like it was set by default). Then I used ACF to create a field group. This group only consists of one field called price (just for this question because I thought I had gone mad when working on this inside my clients project so I created a whole new Wordpress project to isolate the problem as much as possible). I made the field group show when the post_type equals ‘event’.
I see my custom post type being added in wp-admin. I see my field group being there when I manually add a new post of my custom post type. However, when I try to retrieve this custom post type with a GET request in my controller (using Insomnia to call the API), I get the post, but not the ACF fields. This is the only data that I get:
{
"ID": 95,
"post_author": "1",
"post_date": "2022-09-09 15:40:00",
"post_date_gmt": "2022-09-09 15:40:00",
"post_content": "",
"post_title": "Event 1",
"post_excerpt": "",
"post_status": "publish",
"comment_status": "closed",
"ping_status": "closed",
"post_password": "",
"post_name": "auto-draft",
"to_ping": "",
"pinged": "",
"post_modified": "2022-09-09 17:03:40",
"post_modified_gmt": "2022-09-09 17:03:40",
"post_content_filtered": "",
"post_parent": 0,
"guid": "http:\/\/dummydatathroughfakeapiwp.local\/?post_type=event&p=95",
"menu_order": 0,
"post_type": "event",
"post_mime_type": "",
"comment_count": "0",
"filter": "raw"
}
Same goes for the POST request. I’m unable to add any custom fields as data to it. I’m able to create post of the normal post type when using the Wordpress namespace, so perhaps that’s the issue? To be honest I thought it would’ve worked how I created it… but it doesn’t! Any help would be appreciated.