I’m sure there must be a simple answer to this, but after working with this for several days I’m at a loss.
I’m trying to get field values from a custom post type which has custom fields. They are defined in a relationship field which itself is inside a repeater field.
(CPT) Program includes a Semester repeater.
(Repeater) Semester has fields which includes a Course Relationship field.
(CPT) Course has number and text fields.
Here’s the code I’m using:
<?php if( have_rows('semester') ): ?>
<?php while( have_rows('semester') ): the_row(); ?>
<h3><?php the_sub_field('year'); echo ' '; the_sub_field('term'); ?></h3>
<?php
$course = get_sub_field('course');
if( $course ): ?>
<?php foreach( $course as $c ): // variable must NOT be called $post (IMPORTANT) ?>
// works
<h4><?php echo get_the_title( $c->ID ); ?></h4>
// doesn't work
<span class="dp-crs-title"><?php echo the_sub_field('course_title', $c->ID); ?></span>
<span><?php echo the_sub_field('credit_hours', $c->ID); ?></span>
<?php endforeach; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>