I am building a hierarchical menu of custom taxonomies and their related posts using wp_get_nav_menu_items as follow:

if( $locations = get_nav_menu_locations() && isset($locations['secondary']) ):
  $menu = wp_get_nav_menu_object( $locations['secondary'] );

  $menu_items = wp_get_nav_menu_items( $menu->term_id );

  foreach( (array) $menu_items as $key => $menu_item ):
    # access to $menu_item -> title;
    # access to $menu_item -> ID;
    # access to $menu_item -> object_id;
    # etc ...
etc ...

Say I have a menu item called service (it is a term of custom taxonomy solutions_category), and from the Appearance -> Menus I changed its label to 'Our Services' through the Navigation Label. In this case $menu_item->title returns 'Our Services'. How can I get 'service' instead? Because I need it for a subsequent WP_Query to get all posts that belong to custom category 'service'


P.S. I can post full code if you need.

  • Have you tried doing a var_dump() on one of your $menu_item's? I suspect that somewhere in that object will be what you're after. There's a lot of info in the Return Values
    – MBL
    Mar 20, 2014 at 17:04

1 Answer 1


You can try to get that information by using the get_term_by() function with the relevant parameters of the menu item (namely object and object_id) :

foreach( (array) $menu_items as $key => $menu_item )
    // Match the menu items to your custom taxonomy:
    if( 'solutions_category' === $menu_item->object )
        // Fetch the corresponding term object:
        $term = get_term_by( 'term_id', $menu_item->object_id, $menu_item->object );

        // Show the term name:
        echo $term->name;

        // Debug:
        // print_r( $term );

Note that if you don't want to target a special taxonomy, you can replace

    // Match your custom taxonomy:
    if( 'solutions_category' === $menu_item->object )


    // Match only menu items of the type "taxonomy":
    if( 'taxonomy' === $menu_item->type )

where $menu_item->type can have values like taxonomy, post_type, custom (Links), ...

The value of $menu_item->type_label gives you also further information on the menu item type.

Hope this help.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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