How to get main menu only with wp_nav_menu

You can use the depth parameter like this:

wp_nav_menu( array(
    'menu'        => 'header-uk',
    'menu_id'     => 'nav',
    'menu_class'  => 'sitemap',
    'fallback_cb' => false,
    'depth'       => 1,
) );

Or if what you want to do is grab all items to create your own loop/output you can do that as well. Example:

if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ 'header-uk' ] ) ) {

    $menu = wp_get_nav_menu_object( $locations[ 'header-uk' ] );

    if ( ! empty( $menu ) ) {

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

            if ( $menu_items ) {

                foreach ( $menu_items as $key => $menu_item ) {

                    if ( $menu_item->menu_item_parent == 0 ) {

                        echo '<a href="' . esc_url( $menu_item->url ) . '">' . $menu_item->title . '</a>';

                    }

                }

            }

    }

}

The key is in the menu_item_parent check which makes sure an item isn’t a child item before echoing it.

tech