times / acf-to-wp-api

Puts all ACF fields from posts, pages, custom post types, attachments and taxonomy terms, into the WP-API output under the 'acf' key

Home Page:http://wordpress.org/plugins/acf-to-wp-api/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I update a post in rest with their ACF?

opened this issue · comments

Hi,

First of all, very good work with this plugin Chris!
I have read some topics about that but have you find a solution about how create a post in rest with their advanced custom field?
Is it a WP REST API "problem" or can I fix it into your script?

I'am using WP REST API v2.0-beta8, ACF to WP-API 1.3.2 and CPT UI.

Thx
Réda.

Edit: I currently use the update_field() function of the ACF plugin to add manualy my custom field in the data response of the controller. Now, I can POST/PUT (create/update) my ACF fields with WP REST REST.

Réda.

@redacherifi hey great work! just curious, where do you use the update_field() function ? within WP-API or somewhere else ?

Cheers

@EugeneLiang It depends what type of object you will create/edit with REST.
For example, if you want update an ACF field on your post, edit the /rest-api/lib/endpoints/class-wp-rest-posts-controller.php and add the ACF's function update_field() on the method prepare_item_for_database().

@redacherifi can this technique be used for creating acf fields too?

@EugeneLiang update_field() can only change the value of an existing field linked to a post/user... with its key/name. It supose you have already created your ACF field from the backoffice.

For more informations, check the doc : http://www.advancedcustomfields.com/resources/update_field