Support

Account

Home Forums Add-ons Flexible Content Field Wrong Data Being Displayed

Solved

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!

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

The topic ‘Wrong Data Being Displayed’ is closed to new replies.