Title: WP_REST_Post_Format_Search_Handler::prepare_item
Published: December 9, 2020
Last modified: May 20, 2026

---

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

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_post_format_search_handler/prepare_item/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_post_format_search_handler/prepare_item/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_post_format_search_handler/prepare_item/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_post_format_search_handler/prepare_item/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_post_format_search_handler/prepare_item/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_post_format_search_handler/prepare_item/?output_format=md#wp--skip-link--target)

Prepares the search result for a given post format.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_rest_post_format_search_handler/prepare_item/?output_format=md#parameters)󠁿

 `$id`stringrequired

Item ID, the post format slug.

`$fields`arrayrequired

Fields to include for the item.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_post_format_search_handler/prepare_item/?output_format=md#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 permalink URL.
 * `type` string
 * Optional. String `'post-format'`.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_post_format_search_handler/prepare_item/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/search/class-wp-rest-post-format-search-handler.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/rest-api/search/class-wp-rest-post-format-search-handler.php#L105)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/rest-api/search/class-wp-rest-post-format-search-handler.php#L105-L125)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_post_format_search_handler/prepare_item/?output_format=md#related)󠁿

| Uses | Description | 
| [get_post_format_string()](https://developer.wordpress.org/reference/functions/get_post_format_string/)`wp-includes/post-formats.php` |

Returns a pretty, translated version of a post format slug

  | 
| [get_post_format_link()](https://developer.wordpress.org/reference/functions/get_post_format_link/)`wp-includes/post-formats.php` |

Returns a link to a post format index.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_post_format_search_handler/prepare_item/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_post_format_search_handler%2Fprepare_item%2F)
before being able to contribute a note or feedback.