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.




Built from https://develop.svn.wordpress.org/trunk@53010


git-svn-id: http://core.svn.wordpress.org/trunk@52599 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
spacedmonkey 2022-03-29 11:07:11 +00:00
parent 1de43a471c
commit c220f23155
2 changed files with 12 additions and 8 deletions

View File

@ -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();

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.0-alpha-53007';
$wp_version = '6.0-alpha-53010';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.