Support

Account

Home Forums General Issues Relationship Post Object / Post ID

Solving

Relationship Post Object / Post ID

  • Hello,

    I have setup a relationship field setup. The relationship is courses to course-dates

    I would like to use both the Title and the post ID of the parent course when listing the course dates how can I do this? for example

    Course Title | Course ID | Date | Price

  • Hi @joni

    To do that, please check this tutorial: https://www.advancedcustomfields.com/resources/querying-relationship-fields/.

    I hope this helps πŸ™‚

  • Hello,

    Ive tried that but have been unable to show the results nothing appears for the title

    						$date = get_posts(array(
    							'post_type' => 'course-dates',
    							'meta_query' => array(
    								array(
    									'key' => 'course', // name of custom field
    									'value' => '"' . $course_id . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
    									'compare' => 'LIKE'
    								)
    							)
    						));
    
    						?>
    						<?php if( $date ): ?>
    
    							<table>
    								<thead>
    									<tr>
    										<th class="content-pad">Date</th>
    										<th>Time</th>
    										<th>Spaces</th>
    										<th>Price</th>
    										<th>Book</th>
    									</tr>
    								</thead>
    								<tbody>
    							<?php foreach( $date as $dates ): 
    					
    							$spacesleft = get_field('spaces',$dates->ID);?>
    								<tr>
    									<td class="content-pad"><?php the_field('startdate',$dates->ID);?>
    
    									<?php $course_title = get_field('course');
    
    						?>
    						<?php if( $course_title ): ?>
    							<?php foreach( $course_title as $course ): ?>
    								
    										<?php echo get_the_title( $course->ID ); ?>
    							<?php endforeach; ?>
    						<?php endif; ?>
    
  • Hi @joni

    Could you please share the JSON or XML export file of your field group so I can test it out on my end? Also, could you please tell me where you want it to show up? Is it on the course page or the course-dates page?

    Thanks πŸ™‚

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.