corcel: menu doesn't work as expected

as per this post https://github.com/jgrossi/corcel/issues/9, when creating menu items $item->title or $item->post_title does not pull through the expected menu entry. also $item->slug pulls through the slug of the menu item, not the post it relates to

the following issues seem to be present

  • menu item does not show title unless it is changed from the original page name
  • WP creates a nav_menu_item entry in wp_posts so using $item->slug etc gets the slug of the menu item, not the slug of the post the menu item is meant to point to

for every menu item I ended up creating a custom link (instead of a Page/Post/Category menu item) and then linking to $item->meta->_menu_item_url

what would be the correct way to loop through a WP menu with Corcel and get the links to my pages?

thanks j

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 26 (12 by maintainers)

Most upvoted comments

I have same problem, and my solution is find term name by meta _menu_item_object_id:

$menu = \Corcel\Menu::slug('primary')->first();

$menuArray = array();

foreach ($menu->nav_items as $item) {

	$parent_id = $item->meta->_menu_item_menu_item_parent;
	
	if ($item->post_title == '') {
	
		$term_id = $item->meta->_menu_item_object_id;
		
		$term = \Corcel\Term::find($term_id);
		
		$item->post_title = $term->name;
		
	}
	
	$menuArray[$parent_id][] = $item;
	
}