Skip to content

Instantly share code, notes, and snippets.

@loxK
Created July 27, 2010 06:36
Show Gist options
  • Save loxK/491844 to your computer and use it in GitHub Desktop.
Save loxK/491844 to your computer and use it in GitHub Desktop.
function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type' ) {
$object_id = (int) $object_id;
$menu_item_ids = array();
$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,
)
);
foreach( (array) $menu_items as $menu_item ) {
if ( isset( $menu_item->ID ) && is_nav_menu_item( $menu_item->ID ) ) {
if ( get_post_meta( $menu_item->ID, '_menu_item_type', true ) != $object_type )
continue;
$menu_item_ids[] = (int) $menu_item->ID;
}
}
return array_unique( $menu_item_ids );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment