mirror of
git://develop.git.wordpress.org/
synced 2025-01-18 05:18:42 +01:00
Menus: Convert wp_get_nav_menu_items
function to use a taxonomy query.
Change the `wp_get_nav_menu_items` function to replace the call to `get_objects_in_term` with a simple taxonomy query. This change improves performance as it results in one fewer query to retrieve menu items from the database. Props Spacedmonkey, peterwilsoncc. Fixes #55372. git-svn-id: https://develop.svn.wordpress.org/trunk@53010 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
921d2805a0
commit
556492ad88
@ -693,12 +693,11 @@ function wp_get_nav_menu_items( $menu, $args = array() ) {
|
||||
|
||||
static $fetched = array();
|
||||
|
||||
$items = get_objects_in_term( $menu->term_id, 'nav_menu' );
|
||||
if ( is_wp_error( $items ) ) {
|
||||
if ( ! taxonomy_exists( 'nav_menu' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$defaults = array(
|
||||
$defaults = array(
|
||||
'order' => 'ASC',
|
||||
'orderby' => 'menu_order',
|
||||
'post_type' => 'nav_menu_item',
|
||||
@ -706,11 +705,16 @@ function wp_get_nav_menu_items( $menu, $args = array() ) {
|
||||
'output' => ARRAY_A,
|
||||
'output_key' => 'menu_order',
|
||||
'nopaging' => true,
|
||||
'tax_query' => array(
|
||||
array(
|
||||
'taxonomy' => 'nav_menu',
|
||||
'field' => 'term_taxonomy_id',
|
||||
'terms' => $menu->term_taxonomy_id,
|
||||
),
|
||||
),
|
||||
);
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
$args['include'] = $items;
|
||||
|
||||
if ( ! empty( $items ) ) {
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
if ( $menu->count > 0 ) {
|
||||
$items = get_posts( $args );
|
||||
} else {
|
||||
$items = array();
|
||||
|
Loading…
x
Reference in New Issue
Block a user