I have a custom post type called semesters. I created an archive page for that post type called archive-semesters.php. On the template page of archive-semesters.php, I’m trying to get all the fields of each post but when I call the get_fields function it’s returning null.
while ( have_posts() ):
the_post();
$title = get_the_title();
$post_id = get_the_id();
$fields = get_fields( $post_id );
?>
<div>
<?php
echo '<pre>';
var_dump( $post_id );
var_dump( $fields );
echo '</pre>';
?>
</div>
<?php
$count++;
endwhile;
Hey man,
Inside the loop you don’t need to pass the post id argument. Try if just $xxx = get_fields();
And remeber, ” get_fields() ” will only return fields that have value on the post