[wp-hackers] Select pages's associated menu items in a specific menu

Mike Schinkel mikeschinkel at newclarity.net
Tue Jul 27 23:59:15 UTC 2010


So do you mean you have menus where a post may be referenced several times, i.e. that you will have multiple menu items that when selected by the user will load the same post?

-Mike

On Jul 27, 2010, at 7:45 PM, Lox wrote:

> 2010/7/28 Mike Schinkel <mikeschinkel at newclarity.net>:
>> I've read that sentence 5 times and I still can't figure out exactly what you want the query to include. > Can you please elaborate, maybe with some examples?
> 
> Well I have a menu (ID=3) and I am on a page. My scripts needs to get
> all menu items associated with current post in a specific menu
> (term_id: 3). The default WP function get associated menu items in ALL
> menus.
> 
> So basically this retrieve menu items associated with current post in
> ANY menu (where object_id is a post ID)
> 
> $query = new WP_Query;
> $menu_items = $query->query(
>   array(
>           'meta_key' => '_menu_item_object_id',
>           'meta_value' => $object_id,
>           'post_status' => 'any',
>           'post_type' => 'nav_menu_item',
>           'showposts' => -1,
>   )
> );
> 
> To prevent looping through the results to exclude menu item not in
> menu id 3, I need to add a parameter to tell WP_QUERY to select only
> the menu item of a specific menu (term_id).
> 
> I hope it is clear enough. Thkx.
> 
> -- 
> Lox
> lox.dev at knc.nc
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list