prepare_item_links example

$fields = $this->get_fields_for_response( $request );

        $data = $handler->prepare_item( $item_id$fields );
        $data = $this->add_additional_fields_to_object( $data$request );

        $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
        $data    = $this->filter_response_by_context( $data$context );

        $response = rest_ensure_response( $data );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $links               = $handler->prepare_item_links( $item_id );
            $links['collection'] = array(
                'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
            );
            $response->add_links( $links );
        }

        return $response;
    }

    /** * Retrieves the item schema, conforming to JSON Schema. * * @since 5.0.0 * * @return array Item schema data. */
Home | Imprint | This part of the site doesn't use cookies.