Loop with array of posts using 'Advanced Custom Fields' plugin

i’m getting in trouble using Advanced Custom Fields (acf) plugin. I’m using the ‘Post Object’ using more less this code:

<?php

/*
*  View array data (for debugging)
*/

var_dump( get_field('post_objects') );

/*
*  Loop through post objects (assuming this is a multi-select field) ( setup postdata )
*  Using this method, you can use all the normal WP functions as the $post object is temporarily initialized within the loop
*  Read more: http://codex.wordpress.org/Template_Tags/get_posts#Reset_after_Postlists_with_offset
*/

$post_objects = get_field('post_objects');

if( $post_objects ): ?>
    <ul>
    <?php foreach( $post_objects as $post): // variable must be called $post (IMPORTANT) ?>
        <?php setup_postdata($post); ?>
        <li>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            <span>Post Object Custom Field: <?php the_field('field_name'); ?></span>
        </li>
    <?php endforeach; ?>
    </ul>
    <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif;

that is the example code from ACF site.
Problem start when I try to paginate the posts in $post_objects variable because it’s an array of posts but is not possible to apply the

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

beautiful wp loop and I don’t now how to paginate a foreach loop.

Any suggestion?

Francesco

Solutions Collecting From Web of "Loop with array of posts using 'Advanced Custom Fields' plugin"

http://codex.wordpress.org/Function_Reference/paginate_links

  <?php echo paginate_links( $args ) ?> 

Disclaimer: I’m not familiar with the Advance Custom Fields plugin.

The pagination would have to be setup before you enter into the WordPress loop. Taking a count of all the available posts stored inside the the $post_objects, you would pass that variable into the paginate_links function.

You’ll also collect the $paged variable from the wp_query object which should be set by default if pagination is working correctly.

There are a couple of other properties that you would have to set as well, but you can reference the link above for full details.