[wp-hackers] hide specific nav items from public users

Lionel Pointet lionel.pointet at globalis-ms.com
Wed Jun 27 13:28:15 UTC 2012


Hi Ryann,

You're right, there are in fact 2 (maybe more?) filters that lets you do 
what you want with the items to be displayed in a nav menu (supposing 
you use the wp_nav_menu function):

 1. wp_get_nav_menu_items:
 2. wp_nav_menu_objects

You get an array of "item" objects which are globally "post" objects but 
with some more attributes...

Hope that helps.
Lionel

Le 27/06/2012 15:20, Ryann Micua a écrit :
> Hi, can you guys help me with this thing I want to do?
>
> So I created this metabox for pages. This metabox has a checkbox "Show 
> to logged in users only". If it's checked, this page should be seen 
> only by logged in users.
>
> I then added this page to the main menu using wp's menu editor.
>
> I can handle the checks in the page template. What I'd like to do 
> though is to be able to "hide" the page from the main nav if the user 
> is not logged in - even if I added it to the main menu.
>
> I could probably hunt for the right filter somewhere but I figured 
> it'd be faster to ask for help from the gurus :) Is there like a 
> filter similar to the "the_posts" filter which gives an array of post 
> objects queried from the database? I sometimes use this filter to hide 
> posts from non-logged in users, so I was hoping there'd be a similar 
> filter in place for nav items which would be useful for modifying the 
> items just before they're displayed..
>
> Thanks so much for your help!
>




More information about the wp-hackers mailing list