0

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>

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


    <h4>done</h4>
    
    </section>
<?php endif; ?>

1 Answer 1

1

Try

$PostID = get_the_ID();
the_field('text_field', $PostID);
1
  • Please edit your answer, and add an explanation: why could that solve the problem?
    – fuxia
    Oct 25, 2020 at 2:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.