Modals using loops and ACF [closed]

You’re right you should be using an id.

I would use a counter in conjunction with get_the_ID();

$arr_posts = new WP_Query( $args );

if ( $arr_posts->have_posts() ) :
$index = 0;
while ( $arr_posts->have_posts() ) : $arr_posts->the_post();

  echo $index . '_' . get_the_ID();

  endwhile;
endif;

This will give you a unique id which you can use for each item in the loop.

WordPress has a the $index variable built in. We could rewrite this as:

$arr_posts = new WP_Query( $args );

if ( $arr_posts->have_posts() ) :

while ( $arr_posts->have_posts() ) : $arr_posts->the_post();

  echo $arr_posts->current_post . '_' . get_the_ID();

  endwhile;
endif;