WP_REST_Post_Format_Search_Handler::prepare_item()publicWP 5.6.0

Prepares the search result for a given post format.

Method of the class: WP_REST_Post_Format_Search_Handler{}

No Hooks.

Return

Array. Associative array containing fields for the post format based on the $fields parameter.

Usage

$WP_REST_Post_Format_Search_Handler = new WP_REST_Post_Format_Search_Handler();
$WP_REST_Post_Format_Search_Handler->prepare_item( $id, $fields );
$id(string) (required)
Item ID, the post format slug.
$fields(array) (required)
Fields to include for the item.

Changelog

Since 5.6.0 Introduced.

WP_REST_Post_Format_Search_Handler::prepare_item() code WP 6.5.2

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;
}