在WP-restapi-Wordpress中获取一个数字而不是URL作为带有自定义字段的图像的输出
您好,我正在使用WP-restapi插件获取对自定义字段的Api访问。 除了图像输出,其他一切都正常。我得到的是一个数字而不是URL Function.php在WP-restapi-Wordpress中获取一个数字而不是URL作为带有自定义字段的图像的输出,wordpress,rest,Wordpress,Rest,您好,我正在使用WP-restapi插件获取对自定义字段的Api访问。 除了图像输出,其他一切都正常。我得到的是一个数字而不是URL Function.php register_rest_field( 'team', 'company_logo', array( 'get_callback' => 'slug_get_field', 'update_callback' => null,
register_rest_field( 'team',
'company_logo',
array(
'get_callback' => 'slug_get_field',
'update_callback' => null,
'schema' => null,
)
);
}
function slug_get_field( $object, $field_name, $request ) {
return get_post_meta( $object[ 'id' ], $field_name, true );
}
company_徽标是图像的自定义字段,由自定义内容类型管理器制作
这就是我作为JSON检索的内容
{
"id": 10,
"title": {
"rendered": "Giel"
},
"content": {
"rendered": ""
},
"company_logo": "16",
"company_bg": "11"
}
请帮忙,谢谢 我想你需要打电话
wp_get_attachment_url() or wp_get_attachment_image_src()
使用
对象['id']
,因为这将返回完整的图像url。我想您需要调用
wp_get_attachment_url() or wp_get_attachment_image_src()
使用对象['id']
,因为这将返回完整的图像url