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. git-svn-id: https://develop.svn.wordpress.org/trunk@32294 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
7add279793
commit
c3ea088948
|
@ -585,7 +585,10 @@ function wp_get_nav_menu_items( $menu, $args = array() ) {
|
||||||
|
|
||||||
if ( ! empty( $terms ) ) {
|
if ( ! empty( $terms ) ) {
|
||||||
foreach ( array_keys($terms) as $taxonomy ) {
|
foreach ( array_keys($terms) as $taxonomy ) {
|
||||||
get_terms($taxonomy, array('include' => $terms[$taxonomy]) );
|
get_terms( $taxonomy, array(
|
||||||
|
'include' => $terms[ $taxonomy ],
|
||||||
|
'hierarchical' => false,
|
||||||
|
) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset($terms);
|
unset($terms);
|
||||||
|
|
|
@ -117,6 +117,25 @@ class Test_Nav_Menus extends WP_UnitTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_wp_get_nav_menu_items_with_taxonomy_term() {
|
||||||
|
register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );
|
||||||
|
$t = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
|
||||||
|
$child_terms = $this->factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax', 'parent' => $t ) );
|
||||||
|
|
||||||
|
$term_menu_item = wp_update_nav_menu_item( $this->menu_id, 0, array(
|
||||||
|
'menu-item-type' => 'taxonomy',
|
||||||
|
'menu-item-object' => 'wptests_tax',
|
||||||
|
'menu-item-object-id' => $t,
|
||||||
|
'menu-item-status' => 'publish'
|
||||||
|
) );
|
||||||
|
|
||||||
|
$term = get_term( $t, 'wptests_tax' );
|
||||||
|
|
||||||
|
$menu_items = wp_get_nav_menu_items( $this->menu_id );
|
||||||
|
$this->assertSame( $term->name, $menu_items[0]->title );
|
||||||
|
$this->assertEquals( $t, $menu_items[0]->object_id );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ticket 29460
|
* @ticket 29460
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue