The following loop is running successfully and shows no syntax error in my editor, but it's breaking only the Advanced Custom Fields PHP that comes after it (all the ACF before it works fine, and everything after except ACF works fine).
<?php
$args=array(
'post_type' => 'page',
'post_parent' => '39'
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="project" style="background-image:url('<?php the_field('preview_thumbnail'); ?>')">
<div class="project-overlay" style="background-color:<?php the_field('project_highlight_color'); ?>">
</div>
<div class="project-content">
<h3><?php the_title(); ?></h3>
<p><?php the_field('preview_text'); ?></p>
<a href="<?php the_permalink(); ?>" class="button arrow-right">Read more</a>
</div>
</div>
<?php endwhile; } ?>
Here's an example of what still works after it
<img src="<?php echo get_template_directory_uri(); ?>/images/logo-white.png" />
And here's an example of what's breaking after it (Advanced custom fields code)
<p class="banner-text"><?php the_field('pullout_summary'); ?></p>
Sorry if it's a blatant fix! Thanks in advance.
After a custom query, you need to restore the global
$post
variable of the main query withwp_reset_postdata()
. More info in the Codex.