Holy loop attack Batman! I think you can simplify this a lot:
$the_posts = get_posts( array(
'posts_per_page' => '-1',
'post_type' => 'artists',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'date',
'value' => date( 'Ymd' ),
'compare' => '<',
),
)
));
$the_list = array();
foreach ( $the_posts as $the_post ) {
if ( $artists = get_field( 'artists', $the_post->ID ) ) {
// Build a simple name => link index
foreach ( $artists as $artist )
$the_list[ $artist['artistname'] ] = $artist['artistweb'];
}
}
// Now sort the array by key (artist name)
ksort( $the_list );
echo '<ul>';
foreach ( $the_list as $artist => $link ) {
echo '<li>';
if ( $link )
echo '<a href="' . $link . '">';
echo $artist;
if ( $link )
echo '</a>';
echo '</li>';
}
echo '</ul>';