Home Forums Front-end Issues Repeater / Post Object


Repeater / Post Object

  • On the default post object, I have a custom repeater field ‘collection-article_mitarbeiter’ with a post object sub field ‘article_mitarbeiter’.

    I want to display the title and the url of the post object ‘mitarbeiter’ on each standard single post.

    What I have so far is:

    <?php if ( have_rows( 'collection-article_mitarbeiter' ) ) : ?>
    	<?php while ( have_rows( 'collection-article_mitarbeiter' ) ) : the_row(); ?>
    		<?php $article_mitarbeiter = get_sub_field( 'article_mitarbeiter' ); ?>
    		<?php if ( $article_mitarbeiter ) : ?>
    			<?php $post = $article_mitarbeiter; ?>
    			<?php setup_postdata( $post ); ?> 
    			<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    			<?php wp_reset_postdata(); ?>
    		<?php endif; ?>
    	<?php endwhile; ?>
    <?php else : ?>
    	<?php // No rows found ?>
    <?php endif; ?>

    The code correctly detects how many ‘mitarbeiter’ posts are connected to the default post, but instead shows me the title and URL of the default post. What am I doing wrong?

  • Where is the code located?
    In a template file?
    In a function?
    How is this code called?

  • The code is used in a template (Avada Layout). The code is called via XYZ PHP Code. Thanks

  • You must include global $post; at the top of your code.

  • Hey John, thanks a lot, it works!

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

You must be logged in to reply to this topic.