If you need to get the ID from the current page, you should make use of get_queried_object_id()
which will return the ID of the current queried object.
A new instance of WP_Query
alters the $post
global variable, that is why after your loop you’ll see the value of the last post from your custom query if you a var_dump($post);
This is why it is so important to reset all new instances of WP_Query
as it does change the variables. To do this, just add wp_reset_postdata();
after your custom loop
Remember, if you need a counter, there is a build in loop counter, $current_post
which you can access in your case via $loop->current_post
. Just remember, this counter starts at 0