Make WordPress Core

Opened 11 years ago

Closed 7 years ago

#28642 closed defect (bug) (worksforme)

wp_get_nav_menu_items retrieving empty array

Reported by: furi3r's profile furi3r Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9
Component: Menus Keywords: close
Focuses: Cc:

Description

Hi Guys, I found out this problem and it is a bit weird, I tried to debug, but it looks everything on my side is correct, and is just the function failing.

Environment:
WP_DEBUG on
PHP logs clear
WP latest

Situation:
I use a WP menu on the header. Every template calls to the_header() and inside header.php I call to :
wp_nav_menu(array(

'theme_location' => 'main',
'container' => 'nav',
'menu' => 'main' ));

It works like a charm everywhere but in a specific archive of a custom taxonomy (it works fine for others custom taxonomies).
Trying to debug I empty the full template and leave only the_header() the_footer() to avoid conflicts, still happens the same.

I started to debug using other functions related:

In every archive I get the proper array with the menu in the last call, but in the one failing i get:

var_dump(get_nav_menu_locations());
array(5) { primary?=> int(122) bottom?=> int(124) secondary?=> int(0) mobile-menu?=> int(122) lang?=> int(125) }

var_dump(is_nav_menu(122));
bool(true)

var_dump(wp_get_nav_menu_items('main'));
array(0) { }

Any ideas?

Change History (7)

#1 @furi3r
11 years ago

  • Version changed from 3.9.1 to 3.9

Sorry my WP version is 3.9

This ticket was mentioned in IRC in #wordpress-dev by furi3r. View the logs.


11 years ago

#3 @furi3r
11 years ago

Update:

This is happening in more archives when im performing a search in it.

This archive /xxxx/ is an archive of a taxonomy.
I've just realised the menus are working when loading /xxxx/

But if i perform a search query /xxxx/?search=xxx is when the menus are not loading.

Could be some interference between how this menu works and the fact im using a custom search query?

#4 @chriscct7
9 years ago

  • Keywords close added

Can't replicate

#5 follow-up: @jesseisrad
8 years ago

I CAN reproduce this.

I'm trying to work with this function in the footer template and it works fine on a post page, but not on any taxonomic archive. Returns an empty array on those pages.

I'm on WP 4.8

Last edited 8 years ago by jesseisrad (previous) (diff)

#6 in reply to: ↑ 5 @jesseisrad
8 years ago

apologies, my issue and maybe that of the op is related to this: https://wordpress.org/support/topic/wp-nav-menu-dissapears-in-category-pages-1/

basically there's a pre_get_posts somewhere that needs to have 'nav_menu_item' post-type added to it.

#7 @welcher
7 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Unable to reproduce on trunk. Closing but if this is reproducible, please provide instructions.

Note: See TracTickets for help on using tickets.