I use Advance Custom Fields plugin to create some custom fields.
While creating new post or update post, I need to use api (vimeo) to take values to other custom field.
Example:
- 1 field: ID of video
- 2 field: duration
- 3 field: plays count
I enter value in first field, press “Publish” and use this hook:
add_action( 'save_post', 'vimeo_api', 10, 2 );
function vimeo_api( $post_id, $post ) {
// request to vimeo with video ID
update_post_meta( $post_id, 'video-duration', $vimeo_single['body']['duration']);
update_post_meta( $post_id, 'video-plays', $vimeo_single['body']['stats']['plays'] );
}
If I hard-code vimeo ID – it works!
But I can’t get value from field 1.
For example I can get value of post title like this:
$title = $post->post_type;
But it doesn’t works with ACF field.
In developer tools I see this in “headers” tab, form data:
_wpnonce:83ab5bcf5f
_wp_http_referer:/wp-admin/post.php?post=37&action=edit&message=1
user_ID:1
action:editpost
originalaction:editpost
post_author:1
post_type:video
...
fields[field_5423b0bb92209]:
fields[field_5423aff492207]:103222207
fields[field_5423b04192208]:
fields[field_5424dd92c4f3d]:
This return error Warning: Illegal string offset:
$vimeo_id = $post->fields['field_5423aff492207'];
Solved with acf/save_post hook