0

Im creating a new website, and each of my blog posts have a few ACFs. I don't want the post to be clickable so I it will be the front page only. My AFC work perfectly, but although I have 2 blog posts, for the last page the AFCs are shwon.

Is there an easy fix for this?

my index:

<?php get_header(); ?>
<div id="main">
<hr>
<div id="content">
<?php $work_years = get_field('work_years'); ?>
<?php $image = get_field('image'); ?>
<?php $function = get_field('function'); ?>
<?php $certificates = get_field('certificates'); ?>
<?php $website_link = get_field('website_link'); ?>
<?php include 'postinfo.php';?>
</div>

</div>
<div id="delimiter">
</div>
<?php get_footer(); ?>

And my postinfo which includes the AFCs:

<?php echo $work_years; ?><BR>
<img src="<?php echo $image; ?>"><BR>
<?php echo $function; ?><BR>
<?php echo $certificates; ?><BR>
<a href="<?php echo $website_link;?>">Website</a><BR>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<h4>Posted on <?php the_time('F jS, Y') ?></h4>
<p><?php the_content(__('(more...)')); ?></p>
<hr> <?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?>

closed as off-topic by Michael, Jacob Peattie, cjbj, Jack Johansson, EAMann Dec 25 '17 at 4:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

0

I think your fields still need to be placed inside the while loop, otherwise it will only show data for one post only. When the loop switches to the next article, it won't execute your code ACF fields again as those are not currently inside the loop.

So try something like:

<?php get_header(); ?>
<div id="main">
<hr>
<div id="content">
    <?php
    if ( have_posts() ) {
        while ( have_posts() ) {
            the_post();
    ?>
    <?php $work_years = get_field('work_years'); ?>
    <?php $image = get_field('image'); ?>
    <?php $function = get_field('function'); ?>
    <?php $certificates = get_field('certificates'); ?>
    <?php $website_link = get_field('website_link'); ?>

    <?php include 'postinfo.php';?>

    <?php 
        }
    }else{
    ?>
      <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php
    }
    ?>
</div>

</div>
<div id="delimiter">
</div>
<?php get_footer(); ?>

And the postinfo.php would be:

<?php echo $work_years; ?><br />
<img src="<?php echo $image; ?>"><br />
<?php echo $function; ?><br />
<?php echo $certificates; ?><br />
<a href="<?php echo $website_link;?>">Website</a><br />

<h1><?php the_title(); ?></h1>
<h4>Posted on <?php the_time('F jS, Y') ?></h4>
<p><?php the_content(__('(more...)')); ?></p>
<hr>

BTW, I don't follow why you introduced the file postinfo.php and not have that code all in the first file alone. However, I suppose you got your reasons based on your site.

  • Thank you ! and you're right I could have it all in my first file. That's what I did now :-) – baswijdenesdotcom Dec 8 '17 at 6:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.