WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to print content of all menu items, when displaying menu (or branch of menu as in question about displaying menu branches) ?

enter image description here

Once I click on About Us I wish for new page to display content of all it's children links.

So basically I am looking for a way to get IDs of those posts/pages and use them inside my WP Query.

share|improve this question
Looking at your edit - so which one is it: displaying content when rendering menu or just retrieving IDs? Please clarify and if latter we need to adjust title again. :) – Rarst Aug 23 '12 at 18:29
i need IDs. thanks man – daniel.tosaba Aug 23 '12 at 21:13
you think wp_get_associated_nav_menu_items() might help? – daniel.tosaba Aug 23 '12 at 22:35
up vote 4 down vote accepted

I am lazy to write supporting logic from scratch so I am reusing functions from linked answer on branches:

 * Retrieve IDs of posts in branch of menu.
 * @param mixed  $menu
 * @param string $branch_title
 * @link http://wordpress.stackexchange.com/questions/2802/display-a-portion-branch-of-the-menu-tree-using-wp-nav-menu
 * @return array
function get_post_ids_from_menu_branch( $menu, $branch_title ) {

    $menu_object = wp_get_nav_menu_object( $menu );
    $menu_items  = wp_get_nav_menu_items( $menu_object->term_id );
    $items       = submenu_limit( $menu_items, (object) array( 'submenu' => $branch_title ) );
    $items       = wp_list_filter( $items, array( 'object' => 'post' ) );
    $ids         = wp_list_pluck( $items, 'object_id' );

    return $ids;

// example
var_dump( get_post_ids_from_menu_branch( 'Test menu', 'Level 1' ) );
share|improve this answer
WOW! That's some really good news. Never heard of wp_list_filter & wp_list_pluck but this is just what I was after. Many thanks! You saved the day ;) – daniel.tosaba Aug 24 '12 at 21:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.