Opened 6 years ago
Closed 5 years ago
#44567 closed defect (bug) (fixed)
Image creation via Rest API, including additional data/meta data
Reported by: | apermo | Owned by: | TimothyBlynJacobs |
---|---|---|---|
Milestone: | 5.4 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | has-patch has-unit-tests |
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 (4)
Change History (11)
This ticket was mentioned in Slack in #core-restapi by apermo. View the logs.
6 years ago
This ticket was mentioned in Slack in #core-restapi by apermo. View the logs.
6 years ago
#3
@
5 years ago
- Keywords has-patch has-unit-tests added
- Milestone changed from Awaiting Review to 5.4
- Owner set to TimothyBlynJacobs
- Status changed from new to assigned
- Version changed from 4.9.7 to 4.7
Thanks for the report @apermo!
I've uploaded a patch to add support for setting meta while creating an attachment. Could you let me know if it fixes your issue?
Dummy file for uploading an attachment via rest api including title and a meta value