As far I read in your comment, it isn’t requires for you to handle it with a custom query. So if you register your custom post type with 'has_archive' => true
, then you can just reach the archive of the custom post type at http://www.yourwebsite.com/your-cpt-slug/
.
Important: Remember to flush the rewrite rules after you change somethign related to your permalinks. You can do it just visiting Settings > Permalinks
See how register_post_type works for any doubt, it’s always lighting.