Skip to content

Commit

Permalink
Merge 43940fc into 27f2f44
Browse files Browse the repository at this point in the history
  • Loading branch information
nine-2-five committed Jun 11, 2017
2 parents 27f2f44 + 43940fc commit 314e230
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions includes/wp-api-menus-v2.php
Expand Up @@ -369,7 +369,7 @@ public function get_nav_menu_item_children( $parent_id, $nav_menu_items, $depth
public function format_menu_item( $menu_item, $children = false, $menu = array() ) {

$item = (array) $menu_item;

$menu_item = array(
'id' => abs( $item['ID'] ),
'order' => (int) $item['menu_order'],
Expand All @@ -383,7 +383,7 @@ public function format_menu_item( $menu_item, $children = false, $menu = array()
'description' => $item['description'],
'object_id' => abs( $item['object_id'] ),
'object' => $item['object'],
'object_slug' => get_post( $item['object_id'] )->post_name,
'object_slug' => get_object_slug($item),
'type' => $item['type'],
'type_label' => $item['type_label'],
);
Expand All @@ -394,7 +394,19 @@ public function format_menu_item( $menu_item, $children = false, $menu = array()

return apply_filters( 'rest_menus_format_menu_item', $menu_item );
}


private function get_object_slug($item){
$slug = '';

if($item['type'] == 'taxonomy'){
$slug = get_term( $item['object_id'] )->slug;
}
else {
$slug = get_post( $item['object_id'] )->post_name;
}

return $slug;
}

}

Expand Down

0 comments on commit 314e230

Please sign in to comment.