Open peter-mumford opened 5 years ago
Possibly this issue is a problem in the ACF to REST API plugin. I posted an issue there too: #292.
Maybe it has something to do with how attachments save data—there is no save button. Attachments seem to auto-save.
This is solved by a setting in the custom field group. Solution was here: acf-to-rest-api-example
The fix (setting an additional parameter in the field group location settings to current user--is equal to--logged in) no longer works. This always did seem like an unlikely work around. Possibly recent security updates have invalidated it.
I found a solution to this. I de-activated the ACF to REST API plugin, and added my custom fields to the API this way:
$string_args = array( // if the field is boolean, use 'type' => 'boolean' 'type' => 'string', 'description' => 'A meta key description.', 'single' => true, 'show_in_rest' => true ); register_post_meta( 'attachment', 'doc_name', $string_args );
Then I post like this:
wp.media().id(mediaId).update({ title: mediaTitle, meta: { doc_name: docName } }).then(function( response ) { console.log( response ); })
This is very strange. I can create and update posts and pages. I can set ACF field data on posts and pages. But I can't set data on ACF fields on attachments. Create and update will both post data to attachments, but not the ACF fields.
I'm using this straightforward code:
In this example, the title updates correctly, and the response ID is logged to the console. But the fields do not update.
I can also update custom fields on Posts and Pages without any problem.