• Resolved brendan_balwebco

    (@brendan_balwebco)


    Hi all,

    I have a page template which has four bootstrap modals in the footer, each of which displays ACF content and posts from a particular category.

    The ACF content shows up fine in each modal if I remove the loops. If I add the loops back in then the ACF content in the first modal will show up, because the first ACF content is above the first loop on the page template. But any ACF content on the page after that first loop doesn’t show.

    Pulling my hair out trying to find a solution to this!

    Thanks for your time in reading this.

    https://www.ads-software.com/plugins/advanced-custom-fields/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter brendan_balwebco

    (@brendan_balwebco)

    I have just removed the query_posts(‘category_name=cat-name’); from each query and it works fine – obviously this means that it’s now pulling in the same info on all modals

    Thread Starter brendan_balwebco

    (@brendan_balwebco)

    SOLUTION FOUND

    If anyone is having the same problem I resolved this issue by adding a wp_reset_query:

    <?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>

    …after each loop. For example:

    // Display ACF content for category a
    <?php the_field('category_title_a'); ?
    <?php the_field('category_content_a'); ?>
    
    // Display posts from category a
    <?php $my_query = new WP_Query( 'category_name=cat-name' );
    while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    //extra stuff here
    <?php endwhile; ?>
    
    <?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>

    NB according to the wp_reset_query it would seem that WordPress encourage use of a different method so have a read of that page first.

    THANK YOU SO MUCH BRENDAN! That’s was driving me to drink (literally had to sit back with a beer and look at what was going on) and kept thinking it was just me as I had a custom category only loop prior and thought I did something wrong there.

    – cheers!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Advanced custom fields not showing after loop’ is closed to new replies.