Custom Post Type Loop breaking php

A few points:

  • Instead of while(): endwhile; Use while() { }
  • You didn’t check to see if any posts were found, if($loop->have_posts()){} will do the trick
  • You didn’t cleanup after your query, inside the if statement mentioned above, make a call to wp_reset_postdata(); before your closing brace
  • Avoid generic variables like $query for your args that may already be used elsewhere. $args may be a more appropriate name