Wordpress 在WP Rest API中获取MetaBox值

Wordpress 在WP Rest API中获取MetaBox值,wordpress,rest,wordpress-rest-api,meta-boxes,Wordpress,Rest,Wordpress Rest Api,Meta Boxes,我有一个注册的元框: $meta_boxes[] = [ 'title' => esc_html__( 'Background', 'background' ), 'id' => 'background', 'context' => 'normal', 'post_types' => array('post', 'page'), 'fields' => [ [ '

我有一个注册的元框:

    $meta_boxes[] = [
    'title'   => esc_html__( 'Background', 'background' ),
    'id'      => 'background',
    'context' => 'normal',
    'post_types' => array('post', 'page'),
    'fields'  => [
        [
            'type'             => 'image_advanced',
            'name'             => esc_html__( 'Background', 'background' ),
            'id'               => 'background',
            'max_file_uploads' => 1,
        ],
    ],
];
我正试图获得
MetaBox
值,如下所示:

$query = new WP_Query( $args );


$page = $query->post; // there is a post

$meta = get_post_meta($page->ID, 'background', true); // $page->ID is integer

return [
    'uri' => $uri,
    'ID' => $page->ID,
    'page' => $query->post,
    'meta' => $meta
];
,但
$meta
是一个类似
2225
的整数。 此帖子已填充此元框

如果我尝试使用标准Rest API端点,我会得到以下值:

.... post data
 "meta_box": {
    "background": [
        {
            "width": 150,
            "height": 150,
            "file": "2020/10/163593234-e1603902300928.jpg",
........
我的问题是如何通过带有自定义端点的Rest API获取post MetaBox值,因为,
get\u post\u meta
,返回(我猜)一些关系?

您必须使用:

您可以看到
wp\u get\u attachment\u image\u src
返回值

$meta = get_post_meta( $page->ID, 'background', true ); // $page->ID is integer

if( $meta ) {
    $img = wp_get_attachment_image_src( $meta );
}