ACF: How can I publish values of ACF fields in a loop while using wp_query?


I’m using ACF to add fields to a custom post type.

I’ve created an instance of WP_Query to set up a loop.
Within the loop I can publish the standard fields using the_title() and the_content().
However, the ACF function the_field isn’t publishing values for attached fields.

Neither ‘the_field()’ nor ‘echo the_field()’ products the field values.

So… how exactly can I publish these values?

This is my loop:

$jobs_query = new WP_Query($args) ;

if ($jobs_query->have_posts()) : ?>
    <section id="jobs-list">
        <?php while ($jobs_query->have_posts()) : $jobs_query->the_post(); ?>
            <article class="">
                <h3 class="job-title"><?php the_title()  ?></h3>

        <div class="employer">
            <p><?php  the_field('employer')  ?></p>         

        <div class="job-description">
            <?php echo  the_field('job_description')  ?>
                <p class="job-readmore"><a href="<?php echo get_permalink()  ?>">read more</a></p>
        <?php endwhile; ?>

<?php endif; ?>
Bob 2 years 2020-10-24T19:10:35-05:00 0 Answers 25 views 0

Leave an answer