WP_REST_Post_Format_Search_Handler::prepare_item( string $id, array $fields ): array

In this article

Prepares the search result for a given ID.

Parameters

$idstringrequired
Item ID, the post format slug.
$fieldsarrayrequired
Fields to include for the item.

Return

array Associative array containing all fields for the item.

Source

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

Changelog

VersionDescription
5.6.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.