Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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


*  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:

$post_objects = get_field('post_objects');

if( $post_objects ): ?>
    <?php foreach( $post_objects as $post): // variable must be called $post (IMPORTANT) ?>
        <?php setup_postdata($post); ?>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            <span>Post Object Custom Field: <?php the_field('field_name'); ?></span>
    <?php endforeach; ?>
    <?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?


share|improve this question

closed as off-topic by Milo, ialocin, s_ha_dum May 13 '14 at 16:14

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

get_fields is not a WordPress function and it does not appear to accept any pagination parametres --… – s_ha_dum Nov 18 '12 at 16:10
As it's a plugin, I just wanted to know why aren't you using worpdress Loop, and which field type are you using, because Relationship Field, throws the whole post object. – jepser Aug 19 '13 at 4:30

1 Answer 1

  <?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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.