Support

Account

Home Forums Front-end Issues get_field not working with post excerpt

Solved

get_field not working with post excerpt

    • WillBG

    • July 29, 2013 at 10:09 pm

    Hi there,

    I added

    <?php
    $args = array( ‘posts_per_page’ => 1 );
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) : setup_postdata($post); ?>
    <h2>“><?php the_title(); ?></h2>
    <?php the_content(); ?>
    <?php endforeach; ?>

    to my custom page template and the ACF get_field has stopped working. Does anyone knpw why?

  • Hi!

    Youve not pasted anything about the ACF fields but I’m guessing that these appear below that code and they’re attached to a different post..

    So what you need to do is put this after the endforeach:

    
    wp_reset_postdata();
    
    • WillBG

    • July 30, 2013 at 6:08 pm

    Thanks Jonathan, funnily enough I found this out last minute last night and implemented it and it works! Great help though, I hope this helps others!

Viewing 3 posts - 1 through 3 (of 3 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.