I was wondering what is the problem that I am having with the information retrieval from the back-end. (never had such problem before)
I have made an index.php which consists of get_template_part() partials. To be
<?php get_header(); ?>
<?php get_template_part( 'partials/index', 'slider' );
get_template_part( 'partials/index', 'services' );
get_template_part( 'partials/index', 'work' );
get_template_part( 'partials/index', 'testimonials' );
get_template_part( 'partials/index', 'recent' );
get_template_part( 'partials/index', 'technologies' );
get_template_part( 'partials/index', 'contact' ); ?>
<?php get_footer(); ?>
All those template parts have their own html+php included. It retrieves all the HTML from those partials, but the info that stand on ACF fields, its not retrieved.
index-services.php in "partials" folder example:
<section id="services">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<div class="title">
<h1 class="section-heading text-uppercase">
<?php the_field('service_section_title'); ?>
</h1>
<p class="text-faded">
<?php the_field('service_section_description'); ?>
</p>
<div class="btn btn-primary btn-sm">
<a href="<?php the_field('service_section_button_link'); ?>">Learn more</a>
</div>
</div>
</div>
</div>
</div>
Adding all the link of index-services.php (With repeater field)
Image of retrieved HTML of get_template_part()
And the problem is, that none of those the_field() functions are retrieving the information from the back-end.
I have set field in back-end to be shown in Page as Index (And they are shown, filled)
Am I having a problem with query loops?
Try passing the post ID: <?php the_field($field_name, $post_id); ?>
If you are outside the loop, that could be the problem.
The ACF the_field()
function works inside of loop. It uses $post->ID
to get information attached with any specific post or page. Try passing the post id like the_field('FIELD_NAME', $post->ID);
or in case of repeaters you need to pass post id in repeater loop:
if ( have_rows('FIELD_NAME', $post-ID) ){
while ( have_rows('FIELD_NAME', $post->ID) ): the_row();
the_sub_field('SUB_FIELD_NAME'); // No need to add post ID here
endwhile;
}
I guess that will solve your problem.