Support

Account

Home Forums Add-ons Flexible Content Field Multiple empty posts after one succesfull post_object

Solving

Multiple empty posts after one succesfull post_object

  • Hi,
    This must be a simple thing to solve, but i just can’t get it working so hopefully you can.

    I have a Flexible field functions of which has post object as one of the row_layouts. It calls for a custom post type, which has a repeater field. My goal is that i can create a content areas which can be placed on any page on a website but maintained only via CPT. So that i don’t need to go through every page for the possible updates. It needs a repeater, because i want to be able to post as many columns as needed depending how i wan’t to show things on page. Wether it’s full width one column or two to eight columns.

    The CPT actually displays nicely on page but it posts for about twenty empty after the succesfull one. And that’s the problem. All help appreciated, what i’m missing? Feels like it’s looping the post object for fair amount of times. But why empty?

    Structure of the row layout is as follows:

    <?php elseif(get_row_layout() == "flexible_content"): // ?>
    
    <?php $post_objects = get_sub_field('column_module_object');
    
    if( $post_objects ): ?>
    									
    <?php foreach( $post_objects as $post): ?>
    <?php setup_postdata($post); ?>						
    
    <div class="container">	
    <?php if( get_field('section_title') ): ?>
    <h3 class="section-title"> <?php the_field('section_title'); ?> </h3>
    <?php endif; ?>
    
    <div class="row">
    <?php if( have_rows('column_module') ): ?>
    <?php while( have_rows('column_module') ): the_row(); ?>	
    
    <div class="col col-<?php the_sub_field('col_width'); ?>"> 
    <?php the_sub_field('col_content'); ?>
    </div>
    
    <?php endwhile; ?>	
    <?php endif; ?>
    																
    </div> <!-- /row -->
    </div> <!-- /container -->	
    									
    <?php endforeach; ?>
    <?php wp_reset_postdata(); ?>
    <?php endif; ?>

    `

  • Aight please delete this thread. Allowing multiple posts did the trick, damn i feel stupid atm…

  • Hey MTR_2, I really appreciate that you posted that changing the field to allow multiple post objects solved your issue!
    I was trying to do the same thing you were initially doing, so you saved me a lot of headache by posting another, much more simple, way to go about it. Thanks!

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

The topic ‘Multiple empty posts after one succesfull post_object’ is closed to new replies.