how to specify the menu term_id in wp_query

source : wp-hackers digest # 66,112,4.

post_id = $_GET['post'];
$menu_id = $_GET['menu'];

$term = get_term($menu_id, 'nav_menu');

$menu_items = new WP_Query(
array(
'post_type'   => 'nav_menu_item',
'post_status' => 'any',
'meta_key'    => '_menu_item_object_id',
'meta_value'  => $post_id,
'showposts'   => -1,
'taxonomy'    => 'nav_menu',
'term'        => $term->slug,
)
);

The key thing to notice is that the menu item post records were related both via post meta ( which you figured out ) but also via the "nav_menu" taxonomy by term slug ( which you hadn't included. ) At first I thought it wasn't going to be possible to do it with WP_Query() but after inspecting the SQL I wrote I realized it was indeed possible, at least what I understood that you needed.
 
 
Creative Commons License
This work by maniac.vardhan is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
 
 

0 comments :: how to specify the menu term_id in wp_query

Post a Comment