public function get_item( $request ) {
		$id = (int) $request['id'];
		$post = $this->get_post( $id );

		if ( empty( $id ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) {
			return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post id.' ), array( 'status' => 404 ) );
		}

		$data = $this->prepare_item_for_response( $post, $request );
		$response = rest_ensure_response( $data );

		if ( is_post_type_viewable( get_post_type_object( $post->post_type ) ) ) {
			$response->link_header( 'alternate',  get_permalink( $id ), array( 'type' => 'text/html' ) );
		}

		return $response;
	}
public function get_item( $request ) {
		$id = (int) $request['id'];
		$post = $this->get_post( $id );

		if ( empty( $id ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) {
			return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post id.' ), array( 'status' => 404 ) );
		}

		$data = $this->prepare_item_for_response( $post, $request );
		$response = rest_ensure_response( $data );

		if ( is_post_type_viewable( get_post_type_object( $post->post_type ) ) ) {
			$response->link_header( 'alternate',  get_permalink( $id ), array( 'type' => 'text/html' ) );
		}

		return $response;
	}
public function get_item ( $ request ) { $ id = ( int ) $ request [ 'id' ] ; $ post = $ this -> get_post ( $ id ) ; if ( empty ( $ id ) || empty ( $ post -> ID ) || $ this -> post_type !== $ post -> post_type ) { return new WP_Error ( 'rest_post_invalid_id' , __ ( 'Invalid post id.' ) , array ( 'status' => 404 ) ) ; } $ data = $ this -> prepare_item_for_response ( $ post , $ request ) ; $ response = rest_ensure_response ( $ data ) ; if ( is_post_type_viewable ( get_post_type_object ( $ post -> post_type ) ) ) { $ response -> link_header ( 'alternate' , get_permalink ( $ id ) , array ( 'type' => 'text/html' ) ) ; } return $ response ; }
Get a single post.

@param WP_REST_Request $request Full details about the request.
@return WP_Error|WP_REST_Response
Get a single post .