Using an ACF field from a page within a post loop?


I have a page set up with custom fields using Advanced Custom Fields. One of the fields is a text field for specifying the text for a read more button. Within the page template I have a post query to pull in a post and I would like to use the ACF field for the “Read More” text within this loop. However, because the ACF field is associated with the page, it doesn’t work when I am trying to call it from within the post loop:

<?php query_posts('showposts=1&post_type=post&cat=1'); if ( have_posts() ): ?>
    <?php while ( have_posts() ) : the_post(); ?>
      <h4><?php the_title(); ?></h4>
      <p><?php the_excerpt(); ?></p>
  <a class="btn" href="<?php the_permalink(); ?>">
    <!-- This is the field associated with the page -->
    <?php the_field('readmore_label'); ?>
<?php endwhile; wp_reset_query(); endif; ?>

Is it possible to use the page custom field within the post loop in the page’s template?

, user13286 6 years 2017-05-24T09:27:56-05:00 0 Answers 96 views 0

Leave an answer