Support

Account

Home Forums Front-end Issues ACF fields not displaying after custom loop

Solved

ACF fields not displaying after custom loop

  • Hey guys,

    I have a problem with displaying ACF fields on front-end after a custom loop. I have a static front page and added this code to display some CPT:

    
    <?php
    if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
    } elseif ( get_query_var('page') ) {
    $paged = get_query_var('page');
    } else {
    $paged = 1;
    }
    query_posts( array( 'posts_per_page' => 3, 'post_type' => 'news', 'paged' => $paged ) );
    if ( have_posts() ) : ?>
    
    <?php
    /* Start the Loop */
    while ( have_posts() ) : the_post();?>
    
    <article id="post-<?php the_ID(); ?>" <?php post_class('small-12 medium-10 medium-offset-1 columns'); ?> >
    <div class="one-post">
    <a href="<?php the_permalink(); ?>" title="Przejdź do strony">
    <div class="news-content"><h5><?php the_title(); ?></h5></a>
    <p><?php print get_the_excerpt(); ?></p>
    </div>
    <a class="news-read" href="<?php the_permalink(); ?>"><button class="custom-btn">Więcej</button></a>
    </div><!-- .one-post -->
    </article><!-- #post-## -->
    
    <?php
    endwhile;
    wp_reset_postdata();
    else :
    endif;
    ?>
    

    before that loop and when I remove the loop all ACF fields are displayed correctly. What’s wrong with that code?:)

  • Hi,

    You have to restore the main query with wp_reset_query() instead of wp_reset_postdata().
    Give that a try!

  • Ahh, of course! Thanks for pointing out 🙂

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

You must be logged in to reply to this topic.