Home › Forums › General Issues › Loop through post content from another post › Reply To: Loop through post content from another post
Alright, I did some more tampering and removed the include() and put the same code there like this:
<?php elseif( get_row_layout() == 'apartmentlayout' ): ?>
<?php $featured_posts = get_sub_field('apartmentlink');
if( $featured_posts ): ?>
<ul>
<?php foreach( $featured_posts as $post ):
setup_postdata($post); ?>
<li>
<?php the_title(); ?>
<?php if( have_rows('apartment') ): ?>
<?php while( have_rows('repeater_field_name') ) : the_row(); ?>
<?php the_sub_field('number'); ?>
<?php endwhile; ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php endif; ?>
I still get the same issue with 24 titles after eachother with the title from the current post I’m at.
So I tried this:
<?php elseif( get_row_layout() == 'apartmentlayout' ): ?>
<?php echo '<pre>';
print_r( get_sub_field('apartmentlink') );
echo '</pre>';
die; ?>
<?php endif; ?>
And that on the other hand returns the correct post like this:
WP_Post Object
(
[ID] => 73284
[post_author] => 11
[post_date] => 2022-09-19 08:39:19
[post_date_gmt] => 2022-09-19 06:39:19
[post_content] =>
[post_title] => Content 1
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => content-1
[to_ping] =>
[pinged] =>
[post_modified] => 2022-09-19 08:54:00
[post_modified_gmt] => 2022-09-19 06:54:00
[post_content_filtered] =>
[post_parent] => 0
[guid] => //localhost:3000/?post_type=apartments&p=73284
[menu_order] => 0
[post_type] => apartments
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
So it doesn’t seem to work even without include
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.