I'm searching to display value of an ACF field with a variable ID, but i don't know how to write my code.
<select id="scripts" name="scripts">
<?php
global $post;
$args = array( 'numberposts' => -1,
'post_type'=> 'chantier',);
$posts = get_posts($args);
foreach( $posts as $post ) : setup_postdata($post); ?>
<option value="<? echo $post->ID; ?>"><?php the_title(); ?></option>
<option value="
<? $postidchantier = $post->ID;
$users = get_field('conducteur_de_travaux_du_chantier', $postidchantier);
if ($users) {
foreach ($users as $user) {
$userNAME = $user[display_name];
echo $userNAME;
}}?>"><?php the_title(); ?></option>
</select>
<?php endforeach; ?>
if I replace $postidchantier
by an ID (for example :1153), it works and when I do an echo $postidchantier
I obtain the value 1153. But imposible to insert automatically the ID with my code. Can someone help me?