airesvsg / acf-to-rest-api

Exposes Advanced Custom Fields Endpoints in the WordPress REST API
https://wordpress.org/plugins/acf-to-rest-api/
1.33k stars 111 forks source link

How to add custom data to Post Object #302

Open ycruzb opened 5 years ago

ycruzb commented 5 years ago

I've a custom post type named Destiny, inside this custom post type i've added a repeater custom field called Books with a Post Object type selecting other custom post type named Book. I just want to have destinies and every destiny will have books. I don't have problem with this relationship but how can I add the permalink to the Post Object in order to get this value in the api ? I need the permalink inside the Post Object.

The plugin only returns this information for a Post Object:

ID
post_author
post_date
post_date_gmt
post_content
post_status
comment_status
ping_status
post_password
post_name
to_ping
pinged
post_modified
post_modified_gmt
post_content_filtered
post_parent
guid
menu_order
post_type
post_mime_type
comment_count
filter

Can you help me please ?

ghost commented 5 years ago

Would love to know this as well! It feels some mayor fields (like featured image or taxonomy/category) are missing from Post Object...

airesvsg commented 5 years ago

Hi ycruzb,

Please, use the plugin below: http://github.com/airesvsg/acf-to-rest-api-recursive

Thanks

ycruzb commented 5 years ago

@airesvsg thanks for your reply. Can you give a little bit explanation about how to use it in order to accomplish my requirement ? the documentation of the plugin is very poor. Thanks again.

tsryu commented 5 years ago

I have same trouble with this. Hope this issue solved.

dimanotdemo commented 5 years ago

@ycruzb I had a similar issue to yours I think, but mine involved a custom REST API endpoint for my custom post type. Took me a while to figure it out, and there were similar issues opened in this repo, but nothing that was specific as my problem.

With my custom REST API endpoint, retrieving my custom post type I had made myself, I was only getting the basic fields from the post (not my custom ACF fields). This helped me solve my problem: https://stackoverflow.com/questions/49302366/how-wp-rest-api-custom-endpoint-could-return-custom-post-data.

ycruzb commented 5 years ago

Hi @dima7b, thanks for your reply. I was looking for a solution through this plugin but you are right, your approach is excellent. I'll work using this idea.

Thanks again ;)