我正在为我的自定义帖子类型创建自定义端点,以删除不必要的字段并加快请求速度。我想从我的自定义帖子类型中获取图像url。请检查代码以了解更多信息。我无法获取图像字段。在这个link, 这是我在默认rest api调用中得到的,这是我在自定义端点**(top\\u image的image url)**上想要的。请检查我使用和获取空数据的方法。我哪里做错了?请帮帮我。
以下是我的Rest api代码:
function digital_digievent() {
$args = [
\'numberposts\' => 99999,
\'post_type\' => \'digievent\'
];
$posts = get_posts($args);
$data = [];
$i = 0;
foreach($posts as $post) {
$data[$i][\'id\'] = $post->ID;
$data[$i][\'EventTitle\'] = $post->post_title;
$data[$i][\'EventOrganizeBy\'] = $post->organize_by;
$data[$i][\'EventPlace\'] = $post->event_place;
$data[$i][\'EventDate\'] = $post->event_date;
$data[$i][\'EventTime\'] = $post->event_time;
$data[$i][\'EventContent\'] = apply_filters( \'the_content\', $post->post_content );
$data[$i][\'EventExcerpt\'] = $post->post_excerpt;
$data[$i][\'Slug\'] = $post->post_name;
$data[$i][\'EventLink\'] = get_the_permalink($post->ID);
$data[$i][\'EventDate\'] = $post->post_date;
$data[$i][\'EventGuid\'] = $post->guid;
$data[$i][\'EventFeaturedImage\'][\'thumbnail\'] = get_the_post_thumbnail_url($post->ID, \'thumbnail\');
$data[$i][\'EventFeaturedImage\'][\'medium\'] = get_the_post_thumbnail_url($post->ID, \'medium\');
$data[$i][\'EventFeaturedImage\'][\'large\'] = get_the_post_thumbnail_url($post->ID, \'large\');
$data[$i][\'top_image\'] = $post->ad_1[0][\'top_image\'];
$i++;
}
return $data;
}
add\\u action(\'rest\\u api\\u init\',function(){register\\u rest\\u route(\'myrestapi/v1\',\'digievent\',[\'methods\'=>\'GET\',\'callback\'=>\'digital\\u digievent\',]);
});
What I want is the image url(guid) of both top_image and bottom_image field for ad_1.