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(); ?>
<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’ : ”; ?>”>
ID)) ?>” class=”img-responsive”/>
<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’); ?>
<?php $count++; ?>
<?php endforeach; ?>
<span class=”glyphicon glyphicon-chevron-left” aria-hidden=”true”></span>
<span class=”glyphicon glyphicon-chevron-right” aria-hidden=”true”></span>
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 )
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
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!
Plugin boilerplates can do some of the heavy lifting during initial development. We look at four options to speed up your plugin creation. https://t.co/ZtMsdBxAHw— Advanced Custom Fields (@wp_acf) June 5, 2023
© 2023 Advanced Custom Fields.