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

Lox lox.dev at knc.nc
Tue Jul 27 23:45:03 UTC 2010


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


More information about the wp-hackers mailing list