Skip to content

Commit a8417c0

Browse files
committed
Bug fix: ACF menu item's values present only in parents
1 parent 9a80466 commit a8417c0

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

wp-rest-api-v2-menus.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ function wp_api_v2_menus_dna_test( &$parents, $child ) {
123123
function wp_api_v2_menus_get_menu_items( $id ) {
124124
$menu_items = wp_get_nav_menu_items( $id );
125125

126+
// check if there is acf installed
127+
if ( class_exists( 'acf' ) ) {
128+
foreach ( $menu_items as $menu_key => $menu_item ) {
129+
$fields = get_fields( $menu_item->ID );
130+
if ( ! empty( $fields ) ) {
131+
foreach ( $fields as $field_key => $item ) {
132+
// add all acf custom fields
133+
$menu_items[ $menu_key ]->$field_key = $item;
134+
}
135+
}
136+
}
137+
}
138+
126139
// wordpress does not group child menu items with parent menu items
127140
$child_items = [];
128141
// pull all child menu items into separate object
@@ -142,19 +155,6 @@ function wp_api_v2_menus_get_menu_items( $id ) {
142155
}
143156
} while(count($child_items));
144157

145-
// check if there is acf installed
146-
if ( class_exists( 'acf' ) ) {
147-
foreach ( $menu_items as $menu_key => $menu_item ) {
148-
$fields = get_fields( $menu_item->ID );
149-
if ( ! empty( $fields ) ) {
150-
foreach ( $fields as $field_key => $item ) {
151-
// add all acf custom fields
152-
$menu_items[ $menu_key ]->$field_key = $item;
153-
}
154-
}
155-
}
156-
}
157-
158158
return $menu_items;
159159
}
160160

0 commit comments

Comments
 (0)