Support

Account

Home Forums General Issues Fields not working after WP_Query

Solved

Fields not working after WP_Query

    • Nakkeru

    • October 9, 2016 at 12:42 am

    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>

    • Nakkeru

    • October 9, 2016 at 4:50 am

    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?

    • Key

    • July 19, 2021 at 2:02 pm

    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.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.