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
http://wordpress.org/plugins/acf-to-wp-api/
MIT License
203 stars 24 forks source link

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

Closed ghost closed 8 years ago

ghost commented 8 years ago

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.

ghost commented 8 years ago

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.

EugeneLiang commented 8 years ago

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

Cheers

ghost commented 8 years ago

@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().

EugeneLiang commented 8 years ago

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

ghost commented 8 years ago

@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