LLMS_REST_Posts_Controller::handle_terms( int $object_id, WP_REST_Request $request )
Updates the post’s terms from a REST request.
Description Description
Heavily based on WP_REST_Posts_Controller::handle_terms().
Parameters Parameters
- $object_id
-
(int) (Required) The post ID to update the terms form.
- $request
-
(WP_REST_Request) (Required) The request object with post and terms data.
Return Return
(null|WP_Error) WP_Error on an error assigning any of the terms, otherwise null.
Source Source
File: libraries/lifterlms-rest/includes/abstracts/class-llms-rest-posts-controller.php
protected function handle_terms( $object_id, $request ) { $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_llms_rest' => true ) ); foreach ( $taxonomies as $taxonomy ) { $base = $this->get_taxonomy_rest_base( $taxonomy ); if ( ! isset( $request[ $base ] ) ) { continue; } // We could use LLMS_Post_Model::set_terms() but it doesn't return a WP_Error which can be useful here. $result = wp_set_object_terms( $object_id, $request[ $base ], $taxonomy->name ); if ( is_wp_error( $result ) ) { return $result; } } }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.0.0-beta.3 | Filter taxonomies by show_in_llms_rest property instead of public . |
1.0.0-beta.2 | Filter taxonomies by public property instead of show_in_rest . |
1.0.0-beta.1 | Introduced. |