Home › Forums › Add-ons › Flexible Content Field › Wrong Data Being Displayed
Hi!
I’m having an issue with a flexible content field not pulling the correct data. On the homepage for the site I’m working on, I have a hero group, which has fields for a hero image, text, and a button to open a popup. The field names for the hero button and link are hero_button_text and hero_button_link, respectively. Then, I have a separate homepage content flexible content field. The design of the site calls for buttons to be placed beneath different sections, so I have a button layout that allows a button to be placed underneath a section. The field names are button_text and button_link. For some reason, on the homepage, the data in a button a placed under a section reiterates the hero_button data, instead of the button data I put in the custom field (Learn More, with a link to another page).
This is the code in the front-page.php file. All other sections display the correct data.
<div class="front-page">
<div id="primary" class="content-area">
<main id="main" class="site-main">
<?php // open the WordPress loop
if (have_posts()) : while (have_posts()) : the_post();
if( get_field('hero_image') ):
get_template_part('template-parts/section', 'hero');
endif; ?>
<div class="content-margin">
<?php // are there any rows within our flexible content?
if( have_rows('homepage_content') ):
// loop through all the rows of flexible content
while ( have_rows('homepage_content') ) : the_row();
// FEATURED CONTENT
if( get_row_layout() == 'featured_content' )
get_template_part('template-parts/section', 'featured_content');
// RESULTS
if( get_row_layout() == 'results' )
get_template_part('template-parts/section', 'results');
// GENERIC CONTENT
if( get_row_layout() == 'generic_content' )
get_template_part('template-parts/section', 'generic_content');
// BUTTON
if( get_row_layout() == 'button' )
get_template_part('template-parts/part', 'button');
endwhile; // close the loop of flexible content
endif; // close flexible content conditional ?>
</div>
<?php
endwhile; endif; // close the WordPress loop
?>
</main><!-- #main -->
</div><!-- #primary -->
</div><!-- .front-page -->
The logic pulls this template part, and the page seems to be displaying this – the button is in a section with a class of button-section, but the text and link relate back to the hero button code.
<section class="button-section">
<?php $url = get_field('button_link') ?>
<a class="button" href="<?php echo $url ?>">
<?php the_field('button_text'); ?>
</a>
</section>
Any suggestions would be much appreciated!!
Realized my stupid mistake…needed a get_sub_field instead of get_field!
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.