timple-c
11/29/2017 - 8:08 PM

No Description

No Description

function get_menu_like_array($position,$firstLevelOnly = false){

	$menu_name = $position;
	$locations = get_nav_menu_locations();

	if(isset($locations[ $menu_name ])){

	$menu_id = $locations[ $menu_name ] ;
	$menu_array = wp_get_nav_menu_items($menu_id);
	if(is_array($menu_array)){

		$menuArrayTree = buildTree($menu_array);
		$returnArray = array();

		if($firstLevelOnly){
			foreach($menuArrayTree as $topItem){

				$returnArray[] = $topItem;

			}
		} else {
				$returnArray = $menuArrayTree;
		}

		return $returnArray;
	} else  {

		return array();

	}

	} else {

		return array();

	}

}


function buildTree( array &$elements, $parentId = 0 )
{
    $branch = array();
    foreach ( $elements as &$element )
    {
        if ( $element->menu_item_parent == $parentId )
        {
            $children = buildTree( $elements, $element->ID );
            if ( $children )
                $element->wpse_children = $children;

            $branch[$element->ID] = $element;
            unset( $element );
        }
    }
    return $branch;
}