get certain submenu in wordpress menus

function submenu_get_children_ids( $id, $items ) {

    $ids = wp_filter_object_list( $items, array( 'menu_item_parent' => $id ), 'and', 'object_id' );

    foreach ( $ids as $id ) {

        $ids = array_merge( $ids, submenu_get_children_ids( $id, $items ) );
    }

    return $ids;
}

 $menu_name = 'primary-menu';

    if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
	$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );

	$menu_items = wp_get_nav_menu_items($menu->term_id);

$parent_id = array_pop( wp_filter_object_list( $menu_items, array( 'classes' => array('filter_this') ), 'and', 'ID' ) );
$children  = submenu_get_children_ids( $parent_id, $menu_items );

 

Leave a Reply

Your email address will not be published. Required fields are marked *