Make WordPress Core

Changeset 32294


Ignore:
Timestamp:
04/24/2015 06:57:07 PM (11 years ago)
Author:
boonebgorges
Message:

When priming the cache for taxonomy term nav items, don't fetch term descendants.

Descending the term tree causes unnecessary database queries when priming the
cache for a term with many descendants.

Fixes #31724.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/nav-menu.php

    r31748 r32294  
    586586                if ( ! empty( $terms ) ) {
    587587                        foreach ( array_keys($terms) as $taxonomy ) {
    588                                 get_terms($taxonomy, array('include' => $terms[$taxonomy]) );
     588                                get_terms( $taxonomy, array(
     589                                        'include' => $terms[ $taxonomy ],
     590                                        'hierarchical' => false,
     591                                ) );
    589592                        }
    590593                }
  • trunk/tests/phpunit/tests/post/nav-menu.php

    r29792 r32294  
    118118        }
    119119
     120        public function test_wp_get_nav_menu_items_with_taxonomy_term() {
     121                register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );
     122                $t = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
     123                $child_terms = $this->factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax', 'parent' => $t ) );
     124
     125                $term_menu_item = wp_update_nav_menu_item( $this->menu_id, 0, array(
     126                        'menu-item-type' => 'taxonomy',
     127                        'menu-item-object' => 'wptests_tax',
     128                        'menu-item-object-id' => $t,
     129                        'menu-item-status' => 'publish'
     130                ) );
     131
     132                $term = get_term( $t, 'wptests_tax' );
     133
     134                $menu_items = wp_get_nav_menu_items( $this->menu_id );
     135                $this->assertSame( $term->name, $menu_items[0]->title );
     136                $this->assertEquals( $t, $menu_items[0]->object_id );
     137        }
     138
    120139        /**
    121140         * @ticket 29460
Note: See TracChangeset for help on using the changeset viewer.