• Hi everyone I’ve got a bit of a tricky dilemma which on the face of it should be simple to solve. I’m developing a plugin and want to get the unique menu ID when I land on a page. I can use this to get it:

    $menu = wp_get_nav_menu_items($menu_id,array(
       'posts_per_page' => -1,
       'meta_key' => '_menu_item_object_id',
       'meta_value' => $post->ID // the currently displayed post
    ));
    
    var_dump($menu[0]->ID);

    The trouble is when I have 2 identical links in the menu. Such as:

    <li id="menu-item-81" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-79 current_page_item menu-item-81"><a href="http://www.website.com/index.php/page/">My Page</a></li>
    
    <li id="menu-item-466" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-79 current_page_item menu-item-466"><a href="http://www.website.com/index.php/page/">My Page</a></li>

    As you can see 2 menu items pointing to the same page but each has a different menu id (81 and 466).

    You may ask why I’ve got 2 links pointing to the same page and the answer is that as the user (inadvertently or otherwise) does have the ability to do it using the WordPress Menus system and therefore I have to plan for it so that it doesn’t break the plugin.

    So basically how can I determine which menu point has been clicked to arrive at that page.

    Really stumped!

    Thanks in advance

    [No bumping. If it’s that urgent, consider hiring someone.]

  • The topic ‘Get the unique menu ID – a tricky challenge!’ is closed to new replies.