`I’m trying to figure a way how to make posts per page work. By default shows all. I’ve tried a bunch of ways but no luck even with putting a second query inside the foreach loop.
From acf documentation https://www.advancedcustomfields.com/resources/relationship/
<?php
$eventposts = new WP_Query( array(
‘post_type’ => ‘artist’, // This is the name of your post type – change this as required,
‘posts_per_page’ => 4,
‘order’ => ‘DESC’,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘location’, // taxonomy name
‘field’ => ‘term_id’, // term_id, slug or name
‘terms’ => 836, // term id, term slug or term name
)
)
) );
while ( $eventposts->have_posts() ) : $eventposts->the_post();
// The content you want to loop goes in here:
?>
<?php
$featured_posts = get_field(‘relation’);
if( $featured_posts ): ?>
<ul>
<?php foreach( $featured_posts as $post ):
// Setup this post for WP functions (variable must be named $post).
setup_postdata($post); ?>
<li>
<a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a>
<span>A custom field from this post: <?php the_field( ‘field_name’ ); ?></span>
</li>
<?php endforeach; ?>
</ul>
<?php
// Reset the global post object so that the rest of the page works correctly.
wp_reset_postdata(); ?>
<?php endif; ?>
<?php endwhile;
wp_reset_postdata();
?>