Support

Account

Home Forums Add-ons Repeater Field get acf field from custom post type within repeater

Solved

get acf field from custom post type within repeater

  • I have an options page with a repeater field.
    Within the repeater field I have a post_object. Checking posts from a custom posttype.
    Everything is working well in the backend.

    On the front-end I want the ACF field from that custom posttype to be displayed
    What am I doing wrong here?

    <?php if( have_rows('pagina_links_footer', 'option') ): ?>
                <ul>
     
                <?php while ( have_rows('pagina_links_footer', 'option') ) : the_row(); ?>   
     
                    <li>
     
                        <?php $post_object = get_sub_field('pagina_link'); ?>
     
                        <?php if( $post_object ): ?>
     
                            <?php $post = $post_object; setup_postdata( $post ); ?>
     
                            <?php echo the_field('link_url'); ?>
     
                            <?php wp_reset_postdata(); ?>
                        <?php endif; ?>
                    </li>
                <?php endwhile; ?>
                </ul>
    <?php endif; ?>
  • Is the post object field set up to allow multiple selections or a single selection?

    Is this code used inside a template file? How is the code included?

  • I got it to work with:

    <?php if( have_rows('pagina_links_footer', 'option') ): ?>
    <ul>
        <?php while ( have_rows('pagina_links_footer', 'option') ) : the_row(); ?>   
        <li>
            <?php $post_object = get_sub_field('pagina_link'); ?>
            <?php if( $post_object ): ?>
            <?php
            $pagina_link_title = get_the_title($post_object->ID);
            $pagina_link_url = get_field('link_url', $post_object->ID);
            ?>
                <a href="<?php echo $pagina_link_url;?>"><?php echo $pagina_link_title;?></a>
            <?php endif; ?>
        </li>
        <?php endwhile; ?>
    </ul>
    <?php endif; ?>
  • My guess here, because of the way you got it to work, is that in the first code you are using the global variable $post somewhere that it is not defined.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.