Make WordPress Core

Opened 14 years ago

Closed 13 years ago

#14438 closed enhancement (worksforme)

Allow term_id in Wp_query

Reported by: dreadlox's profile DreadLox Owned by:
Milestone: Priority: normal
Severity: major Version:
Component: Query Keywords:
Focuses: Cc:

Description

Hello,

A parameter 'term_id' is missing in wp_query. Instead of:

$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,

)

);

We should be able to do:

$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_id' => $menu_id,

)

);

It saves the overload of using an additional query with get_term function.

Change History (2)

#1 @nacin
14 years ago

I somewhat followed the wp-hackers chain and came to this quick conclusion --

I'm not sure if term_id is necessary. Regardless, I would much rather add an argument to get_associated_nav_menu_items(), or a new function, that achieves what you want, which is to restrict by menu.

It is much better to *not* rely on the internal storage mechanism, and instead focus on how we can improve the API you should rely on.

#2 @nacin
13 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.