Support

Account

Home Forums Add-ons Flexible Content Field Using post custom fields in a Flexible content field

Helping

Using post custom fields in a Flexible content field

  • Hi there,

    I am successfully pulling in my flexibly content field and the sub fields.

    I also manage to pull in a list of the posts using a relationship field.

    Using the code below I do this:

    <?php while(has_sub_field("flexible_content")): ?>
    			<?php if(get_row_layout() == "text_box"): ?>
    				<p class="default-header">
    					<?php the_sub_field("text_box_intro_text"); ?>
    				</p>
    				<p><?php the_sub_field("text_box_main_content"); ?></p>
    				</div>
    				<?php elseif(get_row_layout() == "people_cards"): ?>
    					
    					<div>
    									 
    						<?php if(get_sub_field("select_people_cards")): ?>
    							<ul>
    							<?php foreach(get_sub_field("select_people_cards") as $p): ?>
    								<li><a href="<?php echo get_permalink($p->ID); ?>"><?php echo get_the_title($p->ID); ?></a></li>
    								 <li><?php the_field('person_intro_text'); ?></li>
    							<?php endforeach; ?>
    							</ul>
    						<?php endif; ?>
    			 
    					</div>					
    					
    			<?php endif; ?>
    		<?php endwhile; ?>
    

    What I am having problems is on the line where I use <?php the_field(‘person_intro_text’); ?> – there I am trying to pull in a custom field that the resulting post has.

    E.g. My flexi field shows a list of posts using relationship field.
    Each of those posts have a custom field called person_intro_text, that is the field I am trying to show.

    Are you able to tell me where I am going wrong?

    Thanks,
    Matt

  • Hi @shrimp144

    Just like you pass the $p->ID to the title function, you need to do the same with ACF:

    
    <?php the_field('person_intro_text', $p->ID); ?>
    

    Thanks
    E

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

The topic ‘Using post custom fields in a Flexible content field’ is closed to new replies.