WP_REST_Meta_Fields::get_value( int $object_id, WP_REST_Request $request ): array
- Since
- 4.7.0
- Source
wp-includes/rest-api/fields/class-wp-rest-meta-fields.php:79
Retrieves the meta field value.
Parameters
$object_idint- Object ID to fetch meta for.
$requestWP_REST_Request- Full details about the request.
Return
array- Array containing the meta values keyed by name.
Uses · 4
- get_metadata()Retrieves the value of a metadata field for the specified object type and ID.
- WP_REST_Meta_Fields::get_registered_fields()Retrieves all the registered meta fields.
- WP_REST_Meta_Fields::get_meta_type()Retrieves the object meta type.
- WP_REST_Meta_Fields::prepare_value_for_response()Prepares a meta value for a response.
Source
public function get_value( $object_id, $request ) { $fields = $this->get_registered_fields(); $response = array(); foreach ( $fields as $meta_key => $args ) { $name = $args['name']; $all_values = get_metadata( $this->get_meta_type(), $object_id, $meta_key, false ); if ( $args['single'] ) { if ( empty( $all_values ) ) { $value = $args['schema']['default']; } else { $value = $all_values[0]; } $value = $this->prepare_value_for_response( $value, $request, $args ); } else { $value = array(); if ( is_array( $all_values ) ) { foreach ( $all_values as $row ) { $value[] = $this->prepare_value_for_response( $row, $request, $args ); } } } $response[ $name ] = $value; } return $response; }History
Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.