Getting page slug

  1. If you are inside the loop, you don’t need to access global $post, you already have $post variable accessible in your local scope, and this variable holds the data from current loop iteration.

  2. If you are outside the loop, then you need to access global $post first, and it will hold whatever data it was left with (the first post in the loop usually).

As I understand, you’re trying to output the slug of the current post in your custom loop (not main). In this case, just use $post->post_name;