wordpress REST-API upload image to ACF

Question

I created my own API using WordPress Rest-API. I successfully saved all data in wordpress backend but I don’t know how to get and save the data if file/image.

    register_rest_route( 'mlcs/v1', '/save_data', array(
        'methods' => 'POST',
        'callback' => array( $this, 'save_data_post' ),
        'args' => array(
            'name' => array(
                'required' => true,
                'type' => 'string',
            ),
            'image' => array(
                'required' => true,
                'type' => 'string',
            ),
        )
    ) );

public function save_data_post( $request ) {
   $name = $request->get_param('name');
   $image = $request->get_param('image');

   //save the data in ACF
   update_field('name_field', $name ); //text type

   //not saving
   update_field('image_field', $image ); //image type

}
0
Nikko Dela Cruz 3 months 0 Answers 14 views 0

Leave an answer