I added a new custom field to a fields group to be used only to render the homepage. When trying read and display the contents of this field with the code below, nothing happens. I am sure the way to read custom field is how it should be. I don't get any error message. Could you please help fix this? This is being done on a WordPress site.
<div class="bg-white-base relative pt-row pb-row pl pr">
<div class="wrap-x">
<div class="inside mini">
<?php if ( $headline = get_sub_field( 'slider_-_h1' ) ) : ?>
<h2 class="mb color-purple-base">
<?php echo $headline; ?>
</h2>
<?php endif; ?>
<?php if ( $subheadline = get_sub_field( 'slider_-_h2' ) ) : ?>
<h3 class="mb alt-heading h5">
<?php echo $subheadline; ?>
</h3>
<?php endif; ?>
<?php if ( $text_area = get_sub_field( 'slider-_shortcode' ) ) : ?>
<article class="body-area mt2x">
<?php echo $text_area; ?>
</article>
<?php endif; ?>
</div>
</div>
</div>
CodePudding user response:
get_sub_field()
is supposed to be use inside a loop. When you use a group, you may use a loop like :
while( have_rows('hero') ): the_row();
........
endwhile;
Everything is explained here : https://www.advancedcustomfields.com/resources/group/