Support

Account

Home Forums Add-ons Repeater Field Loop through post object in repeater field

Helping

Loop through post object in repeater field

  • Hi there. I’m looking to create a repeater-field where I can pick a post object and structure the data in a way that pleases me =) however all I get out of this is a link to the current page I’m on, with that anchor tag aswell.

    
    <?php if ( have_rows( 'review' ) ) : ?>
    	<?php while ( have_rows( 'review' ) ) :
    		the_row(); ?>
    		
    		<?php if ( $Content = get_sub_field( 'Content' ) ) : ?>
    			<?php echo $Content; ?>
    		<?php endif; ?>
    
    		<?php
    		$review = get_sub_field( 'review' );
    		if ( $review ) :
    			$post = $review;
    			setup_postdata( $post ); 
    			?>
    			<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    			<?php wp_reset_postdata(); ?>
    		<?php endif; ?>
    
    	<?php endwhile; ?>
    <?php endif; ?>

    I tried using print_r, and it seems I’m fetching the post correctly, so I don’t understand why it’s not working.. any suggestions?

    This is my print_r result

    WP_Post Object ( [ID] => 57 [post_author] => 1 [post_date] => 2022-05-17 19:07:10 [post_date_gmt] => 2022-05-17 19:07:10 [post_content] => [post_title] => review1 [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => review1 [to_ping] => [pinged] => [post_modified] => 2022-05-17 19:07:10 [post_modified_gmt] => 2022-05-17 19:07:10 [post_content_filtered] => [post_parent] => 0 [guid] => https://experimental.ehandels.expert/?post_type=review&p=57 [menu_order] => 0 [post_type] => spelbolag [post_mime_type] => [comment_count] => 0 [filter] => raw ) Sample Page

  • Where is your code located? Is it inside of a function? Is the global $post available before you do $post = $review;?

    Test: Before your repeater loop do var_dump($post);

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

You must be logged in to reply to this topic.