$post
in the callback function is an array, not an object. So you cannot use $post->id
. Change it to $post['id']
and it should work:
function slug_get_phone_number($post, $field_name, $request)
{
return get_post_meta($post['id'], '_phone', true);
}
I recommend to change _phone
to phone_number
or something else without underscore prefix. Because _
is often used with private meta keys. Try to add a custom field which has meta key with _
prefix directly to your post, you will see what I meant.