0
votes

I have the following loop that utilises Advanced custom fields (ACF) - Everything displays except the content. I have tried various solutions with no success.

<?php
          $posts = get_posts(array(
            'numberposts' => -1,
            'post_type' => 'sectors',
            'orderby' => 'menu_order',
            'order' => 'ASC'
          ));
          global $post;
          if($posts) {
            ?>

            <?php
            foreach($posts as $post) {
              ?>
              <div class="content full sector">
                        <?php the_post_thumbnail(); ?>
                        <h2><?php the_title(); ?></h2>
                        <p><?php the_content(); ?></p>
                    </div>
              <?php
            }
            ?>

             <?php
          }
          wp_reset_postdata();
        ?>

Any help is greatly appreciated.

Thanks

1

1 Answers

1
votes

When you use get_posts() to return post data, some post-related data is not available by default. One of these items is the_content(). This is resolved by calling an internal function setup_postdata(), with the $post array as its argument.

Solution: Add setup_postdata( $post ); within your foreach().

Read more in the Codex.