Skip to content

Commit b5772ea

Browse files
author
Fifciuu
committed
Thumbnail src for childs items
1 parent 6c7d59b commit b5772ea

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

wp-rest-api-v2-menus.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/*
33
Plugin Name: WP-REST-API V2 Menus
4-
Version: 0.7.3
4+
Version: 0.7.6
55
Description: Adding menus endpoints on WP REST API v2
66
Author: Claudio La Barbera
77
Author URI: https://thebatclaud.io
@@ -146,10 +146,10 @@ function wp_api_v2_menus_get_menu_items( $id ) {
146146
$slug = basename( get_permalink($item->object_id) );
147147
$item->slug = $slug;
148148
if (isset($item->thumbnail_id) && $item->thumbnail_id) {
149-
$item->thumbnailSrc = wp_get_attachment_image_url($item->thumbnail_id, 'post-thumbnail');
149+
$item->thumbnail_src = wp_get_attachment_image_url(intval($item->thumbnail_id), 'post-thumbnail');
150150
}
151151
} else if($item->type == 'taxonomy') {
152-
$cat = get_category($item->object_id);
152+
$cat = get_term($item->object_id);
153153
$item->slug = $cat->slug;
154154
} else if($item->type == 'post_type_archive') {
155155
$post_type_data = get_post_type_object($item->object);
@@ -160,6 +160,10 @@ function wp_api_v2_menus_get_menu_items( $id ) {
160160
}
161161

162162
if ( $item->menu_item_parent ) {
163+
if (isset($item->thumbnail_id) && $item->thumbnail_id) {
164+
$item->thumbnail_src = wp_get_attachment_image_url(intval($item->thumbnail_id), 'post-thumbnail');
165+
}
166+
163167
array_push( $child_items, $item );
164168
unset( $menu_items[ $key ] );
165169
}
@@ -237,4 +241,4 @@ function wp_api_v2_menus_get_menu_data( $data ) {
237241
'methods' => 'GET',
238242
'callback' => 'wp_api_v2_menu_get_all_locations',
239243
) );
240-
} );
244+
} );

0 commit comments

Comments
 (0)