How to access advance custom fields with post type in a for each loop

enter image description here

I am having a problem accessing my Advanced Custom Fields that I assigned to my post type.

To loop through the posts in my events types I did this:

<?php
   $slider = get_posts(    $slider = g array(
    'post_type' => 'event',
    'posts_per_page' => - 1
   )); ?>
<?php
   $count = 0; ?>
<?php
   foreach($slider as $slide): ?>
<?php
   $title = the_field('event_name'); ?>
<div class="item <?php
   echo ($count == 0) ? 'active' : ''; ?>">
   <img src="<?php
      echo wp_get_attachment_url(get_post_thumbnail_id($slide->ID)) ?>" class="img-responsive yooo"/>
   <div class="carousel-caption">
      <div class="caption-text">
         <hr style="width: 60%;border-bottom: 1px solid #000;margin-top: 0px;margin-bottom: 50px;">
         <img src="<?php
            bloginfo('stylesheet_directory'); ?>/assets/img/icons/note_icon.svg" onerror="this.src='<?php
            bloginfo('stylesheet_directory'); ?>/assets/img/icons/music_note.png'" alt="" class="img-responsive img--center">
         <h4><?php
            echo get_the_title($ID); ?></h4>
         <h4><?php
            the_field('event_date'); ?></h4>
         <p><?php
            the_content(); ?></p>
         <hr style="width: 60%;border-bottom: 1px solid #000;margin-bottom: 0px;margin-top: 50px;">
      </div>
   </div>
</div>
<?php
   $count++; ?>
<?php
   endforeach; ?>

I get the featured image from the post but I cant retrieve the content (text), title or my advanced custom fields.

Read more here:: How to access advance custom fields with post type in a for each loop

Leave a Reply

Your email address will not be published. Required fields are marked *