I have two select created using ACF Pro in a custom post type. I made an archive with a wordpress loop to display those element but depending on the order I declare it, my variable it returns : null. Also if I put it before the_title() witch in case of wp_loop should return the title of post type it return the title of the page.
$stagesId = get_field("stages");
$jobsId = get_field("job");
var_dump($stagesId);
var_dump($jobsId);
In the case it show : 3 and NULL
$jobsId = get_field("job");
$stagesId = get_field("stages");
var_dump($jobsId);
var_dump($stagesId);
In the case it show : 21 and NULL
$args = array(
'post_type' => 'catalogue',
'post_status' => 'publish',
'posts_per_page' => -1,
'order' => 'DESC',
'orderby' => 'post_date'
);
$the_query = new WP_query($args);
$jobs = array(); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php
$jobs[$the_query->post->post_title] = $the_query->post->post_title;
?>
<a href="#contact_form?<?php echo get_the_title() ?>" class="card--link">
<div class="card">
<div class="card--header">
<h3><?php the_title() ?></h3>
</div>
<div class="card--body">
<p><?php the_field("content") ?></p>
<?php
$stagesId = get_field("stages");
$jobsId = get_field("job");
var_dump($jobsId);
var_dump($stagesId);
<p>Nombre de personne disponible pour ces jobs : <?php echo $count ?></p>
</div>
</div>
</a>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif;
Here are how I create my field
array(
'key' => 'field_61386dc51b308',
'label' => 'Job',
'name' => 'job',
'type' => 'select',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
),
'default_value' => array(
),
'allow_null' => 0,
'multiple' => 1,
'ui' => 0,
'return_format' => 'value',
'ajax' => 1,
'placeholder' => '',
),
array(
'key' => 'field_613f0c5df7a97',
'label' => 'Stages',
'name' => 'stages',
'type' => 'select',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
),
'default_value' => array(
),
'allow_null' => 0,
'multiple' => 1,
'ui' => 0,
'return_format' => 'value',
'ajax' => 1,
'placeholder' => '',
),