Query entries from custom post type in an ACF flexible content field

I want to query a custom post type cpt_locations if the office_locations layout is selected in a flexible content field. I’m sure I have the standard syntax, but if I view the page it prints yes many times then hangs – as if it’s looping infinitely. In my content-page.php I have:

if( get_row_layout() == ‘office_locations’ ):

$args = array(
‘post_type’=> ‘cpt_locations’,
‘posts_per_page’ => 10
);

$locations = new WP_Query( $args );
if ( $locations -> have_posts() ) {
while ( $locations -> have_posts() ) {

echo ‘yes’;

}
wp_reset_postdata();
}
wp_reset_query();

endif;

In page.php I’m already in a loop – is this the problem?:

<?php
while ( have_posts() ) :
the_post();

get_template_part( ‘template-parts/content’, ‘page’ );

if ( comments_open() || get_comments_number() ) :
comments_template();
endif;

endwhile;
?>

Read more here:: Query entries from custom post type in an ACF flexible content field

Leave a Reply

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