Home Forums Add-ons Repeater Field Post Object in Repeater Field


Post Object in Repeater Field

  • I have tried looking around and testing some solutions but can’t get this specific problem solved. How can I have a repeater field that will allow users to build a list of pages within the site?
    For example, let’s say I have a repeater field called “quick-links” with a Post Object sub field called “quick-link”. How can I display the link and title of “quick-link”? Is this possible? Am I using the most appropriate field type for the sub field?
    Thanks in advance.

  • Nevermind, just had to dig a little deeper… answer for those searching…

    <?php if( have_rows('quick-links') ): ?>
        <?php while( have_rows('quick-links') ): the_row(); ?>
            <?php $post_object = get_sub_field('quick-link'); ?>
            <?php if( $post_object ): ?>
                <?php // override $post
                $post = $post_object;
                setup_postdata( $post );
                <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
                <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
            <?php endif; ?>
        <?php endwhile; ?>
    <?php endif; ?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Post Object in Repeater Field’ is closed to new replies.