No way to get object ID's
codepuncher opened this issue · 2 comments
codepuncher commented
There is currently no way to get the Post ID for the related nav item.
This prevents getting a field from a page in a menu.
Updating the parse
method allows for this.
protected function parse($items)
{
if (! is_array($items)) {
return;
}
_wp_menu_item_classes_by_context($items);
return $this->tree(
collect($items)
->map(function ($item) {
return (object) [
'parent' => $this->hasParent($item),
'id' => $item->ID,
+ 'db_id' => $item->db_id,
+ 'object_id' => $item->object_id,
'label' => $item->title,
'slug' => $item->post_name,
'url' => $item->url,
'active' => $item->current,
'activeAncestor' => $item->current_item_ancestor,
'activeParent' => $item->current_item_parent,
'classes' => $this->filterClasses($item->classes),
'title' => $item->attr_title,
'description' => $item->description,
'target' => $item->target,
'xfn' => $item->xfn,
];
})
);
}
Log1x commented
Thanks! If you had a chance, would you mind adding it to the readme example?
codepuncher commented
Sure, I'll submit a PR now!