Make WordPress Core

Ticket #14439: nav_menu.patch

File nav_menu.patch, 1.5 KB (added by DreadLox, 14 years ago)

Patch to solve the bug

  • wp-includes/nav-menu.php

     
    642642 * @param string $object_type The type of object, such as "taxonomy" or "post_type."
    643643 * @return array The array of menu item IDs; empty array if none;
    644644 */
    645 function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type' ) {
     645function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type', $menu_id=0 ) {
    646646        $object_id = (int) $object_id;
    647647        $menu_item_ids = array();
    648648
     649    $query_args = array(
     650                                'meta_key' => '_menu_item_object_id',
     651                                'meta_value' => $object_id,
     652                                'post_status' => 'any',
     653                                'post_type' => 'nav_menu_item',
     654                                'showposts' => -1,
     655                          );
     656
     657    if( $menu_id ) {
     658            $term = get_term($menu_id, 'nav_menu');
     659                $query_args = array_merge($query_args, array( 'taxonomy' => 'nav_menu', 'term' => $term->slug) );
     660        }
     661
    649662        $query = new WP_Query;
    650         $menu_items = $query->query(
    651                 array(
    652                         'meta_key' => '_menu_item_object_id',
    653                         'meta_value' => $object_id,
    654                         'post_status' => 'any',
    655                         'post_type' => 'nav_menu_item',
    656                         'showposts' => -1,
    657                 )
    658         );
     663        $menu_items = $query->query( $query_args);
     664
    659665        foreach( (array) $menu_items as $menu_item ) {
    660666                if ( isset( $menu_item->ID ) && is_nav_menu_item( $menu_item->ID ) ) {
    661667                        if ( get_post_meta( $menu_item->ID, '_menu_item_type', true ) != $object_type )