Yoast\WP\SEO\Routes

Meta_Search_Route::search_meta()publicYoast 1.0

Searches meta fields of a given post.

{} Это метод класса: Meta_Search_Route{}

Хуков нет.

Возвращает

WP_REST_Response.

Использование

$Meta_Search_Route = new Meta_Search_Route();
$Meta_Search_Route->search_meta( $request );
$request(WP_REST_Request) (обязательный)
The REST request.

Код Meta_Search_Route::search_meta() Yoast 19.7.1

public function search_meta( $request ) {
	$post_id = $request['post_id'];
	$query   = $request['query'];
	$meta    = \get_post_custom( $post_id );
	$matches = [];

	foreach ( $meta as $key => $values ) {
		if ( \substr( $key, 0, \strlen( $query ) ) !== $query ) {
			continue;
		}

		if ( empty( $query ) && \substr( $key, 0, 1 ) === '_' ) {
			continue;
		}

		// Skip custom field values that are serialized.
		if ( \is_serialized( $values[0] ) ) {
			continue;
		}

		$matches[] = [
			'key'   => $key,
			'value' => $values[0],
		];

		if ( \count( $matches ) >= 25 ) {
			break;
		}
	}

	return \rest_ensure_response( [ 'meta' => $matches ] );
}