0

I'm having a bit of trouble getting acf content to show within the Wordpress loop. The code I'm using within the page.php template is as follows:

<?php $args = array (
'post_type' => 'test-box'
);
$the_query = new wp_query ( $args);
?>
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query-   >the_post(); ?>

<?php 
the_field( 'acf_test_box_header' );
the_field( 'acf_test_box_content' );
?>

<?php endwhile; else : ?>

<p>There are no posts to display.</p>

<?php endif; ?>

The problem is that the two fields: acf_test_box_header and acf_test_box_content don't display their content when inside the loop, returning instead 'header 2' and 'content 2'. If I move them outside the loop then they display the content as it was entered fine.

Any ideas?

6
  • maybe try this the_field( 'acf_test_box_header', get_the_ID ()) ? Commented Feb 29, 2016 at 16:42
  • Your if statement is not correct. if ( $the_query->have_posts() ) : Commented Feb 29, 2016 at 16:44
  • Nope - not making any difference sadly. Commented Feb 29, 2016 at 16:44
  • Similarly, with the_query modified, still the same :-( Commented Feb 29, 2016 at 16:45
  • Maybe this: $current_id = get_the_ID(); the_field( 'acf_test_box_content', $current_id ); Commented Feb 29, 2016 at 16:49

1 Answer 1

1

Try this:

$current_id = get_the_ID(); 
the_field( 'acf_test_box_content', $current_id );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.