1

I am new with WordPress so apologize if i am doing this in a wrong way. I have lot of taxonomies and posts types. I am using one term (from any of the taxonomy) in more then one places in my menu but i want to implement post loop depending on menu id and all its parent id. I am getting menu id with this code.

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

}

Then i am getting menu title and its parent menu title and then implement WordPress tax_query to implement loop to display posts accordingly.

Every thing works perfectly but i have only issue when i am using term in more then one places because it always return id of first occurrence of this term in my menu. The reason behind this is that "current-menu-item" class is assigned to all occurrence of this term in my menu. When this happen my loop could not show correct posts. According to my view this class should assigned to only my currently active menu item instead of all occurrence of this term. I ll need your suggestion to fix this issue. Your help will be much appreciated. Thank you!

  • what is the difference between the 2 pages with the same term in menu ? – mmm Nov 4 '17 at 8:34
  • Thank you for your time. But my client have 4 level menu and want to add terms directly to menu without creating any page. He has a large network of word press sites, lot of taxonomies and terms and wants an automated process and less automated work. – wpdd Nov 4 '17 at 9:11
  • I am using tax query with AND condition among these terms. So i am getting menu id and then title (as term title) to use this in this condition. Only issue for me is to when i have one term with multiple occurrence because above function always return id of first appearance of this term in menu. – wpdd Nov 4 '17 at 9:14

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.