Home › Forums › ACF PRO › Flexible content – relationship – custom field value not getting › Reply To: Flexible content – relationship – custom field value not getting
See my comments inside the code and answer the question
I'm assuming that we are referring to the main post here I will refer to this as post #1 'content_blocks' is on post #1 <?php if( get_field('content_blocks', 24) ): ?> <?php while( has_sub_field('content_blocks', 24) ): ?> <?php $posts = get_sub_field('related_practice'); if( $posts ): ?> <?php foreach( $posts as $post): ?> <?php setup_postdata($post); ?> The code is not looking at a related post I will call this post #2 All calls to all functions inside the loop refer to post #2 if you are trying to get values related to post #1 they will not work <div class="box" style="background-image: url(<?php the_sub_field('background_image');?>)"> <div class="mask"> <div class="content"> <div class="title"><?php the_title(); ?></div> <div class="description"><?php the_sub_field('title');?></div> <a href="<?php echo get_page_link( $page->ID ); ?>" class="more">Learn Name</a> </div> </div> </div> <?php endforeach; ?> <?php wp_reset_postdata(); ?> <?php endif; ?> <?php endwhile; ?> <?php endif;?>
is ‘background_image’ from post #1 or #2
are you trying to get the title from post #1 or #2
the the sub field ‘title’ from post #1 or #2
are you trying to get the page link from post #1 or post #2
I’m only guessing, but your question leads me to believe that you’re trying to get information for post #1 inside the post #2 loop and that’s the reason it’s failing?
It that’s not the case then let me know. If it is the case then you’re going to need to rework these loops so that you’re getting the data you want at the right time.
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!
© 2022 Advanced Custom Fields.