Get posts by menu ID

I recently needed the same thing, I had menu of categories and I needed to get the categories that in the menu. After a several hours digging in the WP core, I found the
wp_get_nav_menu_items() function that helped me.

I finnally came with this, 220 was my menu_id

$navcat = wp_get_nav_menu_items('220');
    foreach ($navcat as $obj) {
        $catid = $obj->object_id;
        $category = get_category($catid);
        ...
        ...
    }

So, if you have a nav menu of posts, I assume you can do the same, something like this should work –

$nav_items = wp_get_nav_menu_items('220');  
    foreach ($nav_items as $obj) {
        $objid = $obj->object_id;
        $postobj = get_post($objid);

        //do stuff with the post..
    }

I think it can save you some complexed mySQL query…

Leave a Comment