Home › Forums › General Issues › Fields not working after WP_Query
I have a WP_Query to load custom type posts to the page. Weirdly, after I end that loop, non of the custom fields work.
Can anyone help, please?
Here is my code:
<div class=”testimonials section text-center alt-bg”>
<div class=”row”>
<h2 class=”section-title”><?php the_field(‘testimonials_section_title’);?></h2>
<div class=”medium-8 small-centered columns”>
<?php
$args1 = array( ‘post_type’ => ‘Testimonial’, ‘posts_per_page’ => 12, ‘order’ => ‘ASC’ );
$loop1 = new WP_Query( $args1 );
while ( $loop1->have_posts() ) : $loop1->the_post(); ?>
<?php the_field(‘text’);?>
<p class=”name”><?php the_field(‘name’);?>
<p class=”company”><?php the_field(‘company’);?>
<?php endwhile; ?>
</div>
</div>
</div>
<h2 class=”section-title”><?php the_field(‘awards_section_title’);?></h2>
Yup, that worked. I’ve read the docs to understand what it does. Makes sense actually. I’m still learning my way through WordPress.
Thanks!
Everyone needs to start somewhere. The things I know the best are the ones that gave me trouble, like this one.
I’m having the same problem, but with the
<?php
$images = get_field('clients_home');
$size = 'full'; // (thumbnail, medium, large, full or custom size)
foreach( $images as $image ): ?>
<?php echo wp_get_attachment_image( $image['ID'], $size ); ?>
<?php endforeach; ?>
</ul>
– the li doesn’t even appear on the html – this happens after several loops. All the loops are closed with the <?php wp_reset_postdata(); ?>.
Any help?
Old post but if it can helps someone, wp_reset_query(); worked for me (instead of wp_reset_postdata();
The topic ‘Fields not working after WP_Query’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.