-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
36 lines (30 loc) · 822 Bytes
/
functions.php
File metadata and controls
36 lines (30 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
//Get Menus Array
function getMenus($location) {
// Get Navigation by Location
$locations = get_nav_menu_locations();
// Fetch menu by id
$menu = wp_get_nav_menu_object($locations[$location]);
$menus = wp_get_nav_menu_items($menu->term_id);
$items = [];
if ($menus) {
// loop on all navigation items
foreach (wp_get_nav_menu_items($menu->term_id) as $item) {
$result = [
'ID' => $item->ID,
'title' => $item->title,
'type' => $item->type,
'url' => $item->url,
'class' => array_shift($item->classes),
'description' => $item->description,
'childs' => [],
];
if ($item->menu_item_parent == 0) {
$items[$item->ID] = $result;
} else {
$items[$item->menu_item_parent]['childs'][$item->ID] = $result;
}
}
}
return $items;
}