I have a lot of taxonomies and I am using one term (from any of the taxonomies) in more than one place in my menu. I want to implement a post loop which depends on the menu id and all its parent ids. I am getting menu id with this code:

add_filter( 'wp_nav_menu_objects', 'wpse16243_wp_nav_menu' );
function wpse16243_wp_nav_menu( $sorted_menu_items ){
foreach ( $sorted_menu_items as $menu_item ) {
    if ( $menu_item->current-menu-item ) {
        $GLOBALS['wpse16243_title'] = $menu_item->ID;
return $sorted_menu_items;

I get the menu title and its parent menu title and then implement WordPress tax_query() to implement a loop to display posts accordingly.

Everything works perfectly, but I have only issue when I am using a term in more than one place, because it always returns the id of first occurrence of this term in my menu. The reason behind this is that current-menu-item class is assigned to all occurrences of this term in my menu. When this happens my loop does not show the correct posts.

It seems to me that the class should only be assigned to my currently active menu item instead of all occurrences of this term. What is the issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.