Wordpress - Get page IDs from nav items
Menu items are stored in the posts
table with a post_type
of nav_menu_item
. So, what you are returning is the ID of the menu item itself, not what it points to.
The page/post ID that the menu item refers to is stored in the postmeta
table, with a post_id
that matches the menu item ID
and meta_key
= _menu_item_object_id
. The easiest way to get the meta_value
(ie the page being pointed to by the menu item) is to use something like this:
$numbers[] = get_post_meta( $menu_item->ID, '_menu_item_object_id', true );