Support

Account

Home Forums ACF PRO Get Next Post Reply To: Get Next Post

  • Your code does not make any sense to me at all, can’t really figure out what your doing.

    assuming that this is checking to see if a repeater has a value

    
    if(get_field('tradeshows', 40) ):
    

    you get a sub field of the current post, however, I do not see any have_rows() loops, so this should return false, unless this loop starts somewhere before the code you’ve included. https://www.advancedcustomfields.com/resources/have_rows/

    
    $current_event_date = get_sub_field('event_date');
    

    Then you do a query based on that value, after the query you have

    
    $rows = get_field('tradeshows', 40);
    $tradeshowslocation = get_sub_field('event_location', 40);
    

    which is getting the value for the same field you checked to make sure it had a value and then you’re getting a sub field of that repeater, but once again, I don’t see any have_rows() loop.

    Then you start looping through your custom query

    
    <?php if ($next_event_query->have_posts()) while ($next_event_query->have_posts()): $next_event_query->the_post(); ?>
    

    At this point, any calls to ACF functions will assume that the post you want to get values from is this post from the custom query and not the original post you were getting values from before the loop. At the same time you’re not even trying to get any values from this new post to display them.

    Your code should go in a sequence that looks something like this, that is if you are looping through a repeater to get information for doing the query.

    
    if (have_rows('repeater')) {
      while (have_rows('repeater')) {
        the_row();
        $current_event_date = get_sub_field('event_date');
        // do your custom query
        // .........
        if ($next_event_query->have_posts()) {
          while ($next_event_query->have_posts()) {
            $next_event_query->the_post();
            // get values and display information about this post
            // of the custom query
          } // end while have posts
          wp_reset_postdata(); // important
        } // and if have posts
      } // end while have rows
    } // end if have rows