In my WordPress site I have a requirement to show private
links in the main navigation (via wp_nav_menu
) even if the user isn't logged in (I just need to show the link, not change who can view the actual content).
I can do this elsewhere, using wp_list_pages and
specifying the post_status(es) I want to display but I can't see how to apply that to wp_nav_menu
.
This works:
wp_list_pages(array(
'title_li' => '',
'child_of' => $page->ID,
'post_status' => 'published,private'
));
Is there a way to do something similar with this?
wp_nav_menu(array(
'menu' => 'primary',
'theme_location' => 'primary',
'container' => FALSE,
'walker' => new MegaMenuWalker
'depth' => 2));
My searches so far show a bunch of ways to post-process the results to filter out private pages (or drafts) using the wp_get_nav_menu_items
hook but I have yet to turn up something on doing the reverse.
I suppose I could do a custom query to grab items that way but that wouldn't let me use my custom walker.
Tantalisingly there's wp_get_nav_menu_items( $menu, $args )
which does allow me to specify the post_status argument, however I'm left to apply my own render rather than being able to use the walker... unless there's some way to use the walker outside the context of wp_nav_menu
?