Home › Forums › Add-ons › Flexible Content Field › 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!
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.