WordPress.org

Make WordPress Core

Opened 11 days ago

#44567 new defect (bug)

Image creation via Rest API, including additional data/meta data

Reported by: apermo Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.7
Component: REST API Keywords:
Focuses: Cc:

Description

When creating a new attachment with the Rest API, that also includes data, normal data like the title will be handled, but additional data, like meta data for example are not handled.

When adding this code near the end of the method create_item() on the file class-wp-rest-attachments-controller.php the issue is solved.

$request->set_url_params( [ 'id' => $id ] );             
                                                               
$response = parent::update_item( $request );             
                                                               
if ( is_wp_error( $response ) ) {                        
        return $response;                                    
}                                                        

I added it prior $fields_update...

Note: Since this requires an upload with data and registered meta, I've added an example file. And you need to register the meta on the website too.

register_meta( 'post', 'my_meta', [
			'type' => 'string',
			'description' => '',
			'single' => true,
			'show_in_rest' => true,
		] );

Attachments (1)

upload_with_attachment.php (1.4 KB) - added by apermo 11 days ago.
Dummy file for uploading an attachment via rest api including title and a meta value

Download all attachments as: .zip

Change History (1)

@apermo
11 days ago

Dummy file for uploading an attachment via rest api including title and a meta value

Note: See TracTickets for help on using tickets.