Home › Forums › Front-end Issues › content in custom fields not showing on live page
Hey … I have embedded my “<?php the_field(”); ?>” in the appropriate places, but they aren’t showing up on the live page. I selected the location as “Post Type” = Slide, so the custom fields show up in the right place. I have 4 sections on my home page. In 2 sections the custom fields are showing on the live page while 2 sections are not. I’ve checked everything and can’t get it to work.
Here is the code:
<?php get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<!–carousel–>
<section>
<div id=”myCarousel” class=”carousel slide” data-ride=”carousel”>
<!– Indicators –>
<!– Wrapper for slides –>
<div class=”carousel-inner” role=”listbox”>
<?php $slider = get_posts(array(‘post_type’ => ‘slider’, ‘posts_per_page’ => 3)); ?>
<?php $count = 0; ?>
<?php foreach($slider as $slide): ?>
<div class=”item <?php echo ($count == 0) ? ‘active’ : ”; ?>”>
<div class=”overlay”></div>
ID)) ?>” class=”img-responsive”/>
<div class=”carousel-caption”>
<h2><?php the_field(‘main_slide_title’); ?></h2>
<p><?php the_field(‘main_sub_title’); ?></p>
<p>” class=”btn btn-lg btn-primary” role=”button”>
<?php the_field(‘main_slide_button’); ?>
</p>
</div>
</div>
<?php $count++; ?>
<?php endforeach; ?>
</div>
<!– Controls–>
<span class=”glyphicon glyphicon-chevron-left” aria-hidden=”true”></span>
<span class=”sr-only”>Previous</span>
<span class=”glyphicon glyphicon-chevron-right” aria-hidden=”true”></span>
<span class=”sr-only”>Next</span>
</div>
</section>
I can’t say for certain if this is the issue but you have an outer loop which is the main loop and holds the Global $post object. You then have an inner loop with a foreach()
. Whenever you call the_field()
it will always pull from the Global $post object unless told otherwise. Your foreach()
doesn’t overwrite this ( you would need to use setup_postdata( $slide )
).
The solution could be, assuming you want to pull field values from the get_posts()
results is to pass the post or post ID into the function call like so:
the_field( 'main_slide_title', $slide )
or
the_field( 'main_slide_title', $slide->ID )
im having a similar issue. previous fields i created are showing on my page and new one arent. even ones uploaded through a .json file
The topic ‘content in custom fields not showing on live page’ is closed to new replies.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.