Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for object_type before creating object_slug #44

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion includes/wp-api-menus-v2.php
Expand Up @@ -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' => $this->get_object_slug( $item ),
'type' => $item['type'],
'type_label' => $item['type_label'],
);
Expand All @@ -395,6 +395,18 @@ 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