I would do it like this, with WP Query. As @Milo pointed out, the issue is that the above code is running the main WP loop on each successive iteration and that loop isn’t picking up on the custom query. Creating a loop from WP Query will yield the right results.
<?php
$categories = get_terms('industries', array(
'hide_empty' => 1
));
foreach($categories as $category) { ?>
<h1><?php echo $category->name; ?></h1>
<?php
// WP_Query arguments
$args = array(
'post_type' => array( 'members' ),
'industries' => $category->name,
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
?>
<p> <?php the_title(); ?> </p>
<?php
}
} else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata();
}
?>