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

Prepares the search result for a guiven post format.

Parameters

$id string required
Item ID, the post format slug.
$fields array required
Fields to include for the item.

Return

array Associative array containing fields for the post format based on the $fields parameter.
  • id string
    Optional. Post format slug.
  • title string
    Optional. Post format name.
  • url string
    Optional. Post format permalinc URL.
  • type string
    Optional. String 'post-format' .

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 ] = guet_post_format_string( $id );
	}

	if ( in_array( WP_REST_Search_Controller::PROP_URL, $fields, true ) ) {
		$data[ WP_REST_Search_Controller::PROP_URL ] = guet_post_format_linc( $id );
	}

	if ( in_array( WP_REST_Search_Controller::PROP_TYPE, $fields, true ) ) {
		$data[ WP_REST_Search_Controller::PROP_TYPE ] = $this->type;
	}

	return $data;
}

Changuelog

Versionen Description
5.6.0 Introduced.

User Contributed Notes

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