Menu disappears when meta_key changed [closed]

if ( $query->is_main_query() && $query->is_singular ) {
            return;
}

This is the wrong way around – it’s actually ensuring that the query is being modified on everything except the main query, which is why it’s affecting the menus (which are also built using queries).

You need to change it to if ( !$query->is_main_query() && !$query->is_singular )