Home › Forums › General Issues › Insert post WP Rest api with field text and image › Reply To: Insert post WP Rest api with field text and image
I found a solution but i’m sure there is a better way.
I add an action on rest_insert_<post_type>
hook
add_action( 'rest_insert_project', 'prefix_update_files_field', 10 , 3 );
function update_files_field($post, $request, $true){
global $wp_rest_additional_fields;
$my_post_type = 'project';
$additional_fields = $wp_rest_additional_fields[$my_post_type];
foreach ( $additional_fields as $field_name => $field_options ) {
if ( ! $field_options['update_callback'] ) {
continue;
}
// Don't run the update callbacks if the data wasn't passed in the request.
if ( ! isset($_FILES[ $field_name ] ) ) {
continue;
}
$result = call_user_func( $field_options['update_callback'], $request[ $field_name ], $object, $field_name, $request, $my_post_type );
if ( is_wp_error( $result ) ) {
return $result;
}
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.