Support

Account

Home Forums General Issues Fields not working after WP_Query

Solved

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();

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.