WP_REST_Post_Format_Search_Handler::prepare_item() WordPress Method
The WP_REST_Post_Format_Search_Handler::prepare_item() method is used to prepare a search result for a post format. This is used to search through the post formats for a specific term.
WP_REST_Post_Format_Search_Handler::prepare_item( string $id, array $fields ) #
Prepares the search result for a given ID.
Parameters
- $id
(string)(Required)Item ID, the post format slug.
- $fields
(array)(Required)Fields to include for the item.
Return
(array) Associative array containing all fields for the item.
Source
File: wp-includes/rest-api/search/class-wp-rest-post-format-search-handler.php
public function prepare_item( $id, array $fields ) { $data = array(); if ( in_array( WP_REST_Search_Controller::PROP_ID, $fields, true ) ) { $data[ WP_REST_Search_Controller::PROP_ID ] = $id; } if ( in_array( WP_REST_Search_Controller::PROP_TITLE, $fields, true ) ) { $data[ WP_REST_Search_Controller::PROP_TITLE ] = get_post_format_string( $id ); } if ( in_array( WP_REST_Search_Controller::PROP_URL, $fields, true ) ) { $data[ WP_REST_Search_Controller::PROP_URL ] = get_post_format_link( $id ); } if ( in_array( WP_REST_Search_Controller::PROP_TYPE, $fields, true ) ) { $data[ WP_REST_Search_Controller::PROP_TYPE ] = $this->type; } return $data; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.6.0 | Introduced. |