Opened 9 years ago
Closed 9 years ago
#38852 closed defect (bug) (fixed)
REST API Unable to Set Parent to 0
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.7 | Priority: | normal |
| Severity: | normal | Version: | 4.7 |
| Component: | REST API | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
Inside of WP_Rest_Posts_Controller::prepare_item_for_database there is a problem around the parent property.
The code checks if the parent is not empty, which, if you are trying to set the parent to 0 it will appear to be empty so the property is never setup for the database update.
// Parent.
if ( ! empty( $schema['properties']['parent'] ) && ! empty( $request['parent'] ) ) {
$parent = get_post( (int) $request['parent'] );
if ( empty( $parent ) ) {
return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post parent ID.' ), array( 'status' => 400 ) );
}
$prepared_post->post_parent = (int) $parent->ID;
}
Attachments (1)
Change History (5)
Note: See
TracTickets for help on using
tickets.
In 39289: