[ADD DATA API] Thêm dữ liệu vào search (ok)

C:\Users\Administrator\AppData\Local\Temp\scp43253\var\www\appypvn\wp-includes\rest-api\endpoints\class-wp-rest-search-controller.php

public function prepare_item_for_response( $id, $request ) {
		$handler = $this->get_search_handler( $request );
		if ( is_wp_error( $handler ) ) {
			return new WP_REST_Response();
		}
		$fields = $this->get_fields_for_response( $request );
		$data = $handler->prepare_item( $id, $fields );
		$data = $this->add_additional_fields_to_object( $data, $request );

		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
		$data    = $this->filter_response_by_context( $data, $context );
		// $data['image'] = wp_get_attachment_url(get_post_thumbnail_id($id),'full');
		$datas = get_post_meta($id);
		$data['webbupointfinderitemfeaturedmarker'] = $datas['webbupointfinder_item_featuredmarker'];
		$data['webbupointfinderitemsaddress'] = $datas['webbupointfinder_items_address'];
		$data['webbupointfinderitemslocation'] = $datas['webbupointfinder_items_location'];
		$data['webbupointfinderitemfieldtelephone'] = $datas['webbupointfinder_item_field_telephone'];
		$data['webbupointfinderitemfieldmobile'] = $datas['webbupointfinder_item_field_mobile'];
		$data['webbupointfinderitemfieldemail'] = $datas['webbupointfinder_item_field_email'];
		$data['webbupointfinderitemfieldwebsite'] = $datas['webbupointfinder_item_field_website'];
		$data['webbupointfinderitemcustommarker'] = $datas['webbupointfinder_item_custom_marker'];
		$data['webbupointfinderitemheaderimage'] = $datas['webbupointfinder_item_headerimage'];
		$data['webbupointfinderitemsliderimage'] = $datas['webbupointfinder_item_sliderimage'];
		$response = rest_ensure_response( $data );

		$links               = $handler->prepare_item_links( $id );
		$links['collection'] = array(
			'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
		);
		$response->add_links( $links );

		return $response;
	}

Last updated