I have a Post Object field in which a list can be selected and I need to display all the selected titles on the page. Now, with my code, nothing is displayed on the page. How can I solve this?
<ul >
<?php
$speaker_sessions = get_field('speaker_sessions');
if( $speaker_sessions ): ?>
<li><?php echo $speaker_sessions->post_title; ?><li>
<?php endif; ?>
</ul>
CodePudding user response:
As noted from the comments, you have an array so you’ll need to iterate over them:
<?php if( $speaker_sessions = get_field('speaker_sessions') ): ?>
<ul >
<?php foreach( $speaker_sessions as $speaker_session ): ?>
<li><?php esc_html_e($speaker_session->post_title); ?><li>
<?php endforeach; ?>
</ul>
<?php endif; ?>