Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to create a custom WordPress Rest Api route.
* mytheme_handle_get_meta_value.
* Handle calls to the Wp Rest Api /meta end-point,
* @see
* @uses get_post_meta()
* @uses WP_Error()
* @uses rest_ensure_response()
* @uses array()
function mytheme_handle_get_meta_value($request)
$post = $request['post'];
$key = $request['key'];
$value = get_post_meta($post, $key, true);
if (!$value)
return new WP_Error('Meta value not found', 'Invalid meta key', array('status' => 404));
return rest_ensure_response(array('meta' => $value));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.