WP_REST_Post_Search_Handler::prepare_item_links() WordPress Method

The prepare_item_links() method is used to prepare the links for a post when it is displayed in a search results. This includes the permalink for the post and the link to the author's page.

WP_REST_Post_Search_Handler::prepare_item_links( int $id ) #

Prepares links for the search result of a given ID.


Parameters

$id

(int)(Required)Item ID.


Top ↑

Return

(array) Links for the given item.


Top ↑

Source

File: wp-includes/rest-api/search/class-wp-rest-post-search-handler.php

	public function prepare_item_links( $id ) {
		$post = get_post( $id );

		$links = array();

		$item_route = rest_get_route_for_post( $post );
		if ( ! empty( $item_route ) ) {
			$links['self'] = array(
				'href'       => rest_url( $item_route ),
				'embeddable' => true,
			);
		}

		$links['about'] = array(
			'href' => rest_url( 'wp/v2/types/' . $post->post_type ),
		);

		return $links;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.