Roots Discourse

Primary Navigation not showing on custom template for custom taxonomy

In my header I have this for my primary nav:

        if (has_nav_menu('primary_navigation')):
          wp_nav_menu([
            'theme_location' => 'primary_navigation',
            'menu_class' => 'navbar-nav justify-content-end pull-right navigation__list navigation__list__header navbar__navigation__list__header',
            'menu_id' => 'header-menu'
          ]);
        endif;

This show fine just about everywhere, however on a custom template I have for displaying some custom post types by taxonomy, the navigation doesn’t show up, the closest thing I have found is in wp-includes/nav-menu-template.php when this is called on this template the $menu-items on line 123 is empty. Any other time it is not. It is passing the same term_id at all times. What am I missing regarding this? Or is there somewhere else I should be looking at? The call to the header is coming from base.php so I’m pulling from the same place at all times.

1 Like

This isn’t returning any menu items not just primary navigation. I added these output lines in nav-menu-template.php

	if ( $menu && ! is_wp_error($menu) && !isset($menu_items) )
{
    write_log($menu);
    $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) );
    write_log($menu_items);
}

This is the output of that from my when on my page taxonomy-location-types.php

[31-Aug-2017 15:27:52 UTC] WP_Term Object
(
    [term_id] => 2
    [name] => Header Menu
    [slug] => header-menu
    [term_group] => 0
    [term_taxonomy_id] => 2
    [taxonomy] => nav_menu
    [description] => 
    [parent] => 0
    [count] => 6
    [filter] => raw
)

[31-Aug-2017 15:27:52 UTC] Array
(
)

[31-Aug-2017 15:27:52 UTC] WP_Term Object
(
    [term_id] => 3
    [name] => Footer One
    [slug] => footer-one
    [term_group] => 0
    [term_taxonomy_id] => 3
    [taxonomy] => nav_menu
    [description] => 
    [parent] => 0
    [count] => 5
    [filter] => raw
)

[31-Aug-2017 15:27:52 UTC] Array
(
)

So it knows the menus exist but doesn’t return any of the items?

This doesn’t make sense and should not happen on a default Sage install. Look at whatever code and plugins you’ve introduced and start removing things?

Yeah, I don’t think it’s necessarily a Sage issue but as you said this doesn’t make sense and I’m just checking to make sure I’m not missing something with Sage. I’ve turned off all plugins that I can(using ACF and that starts breaking the code. going to comment that code to turn it off). Commented just about every extraneous query I can think of. Still , no change.

OK, got it, as suspected it isn’t any issue with Sage but had to do with my pre_get_posts hook.
Also, query monitor is your best friend in debugging.

1 Like