Home › Forums › Front-end Issues › Limit relationship posts per page › Reply To: Limit relationship posts per page
I have the same problem, this is my code, what’s wrong?
<?php
$ids = get_field('correla_blog_post');
$query = new WP_Query(array(
'post_type' => get_post_type(),
'posts_per_page' => 1,
'post__in' => $ids
));
if( $ids ): ?>
<div class="posts-list clearfix">
<?php foreach( $ids as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<article class="post-item">
<figure><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('t300x200'); ?></a></figure>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="entry-excerpt"><p><?php the_field('riassunto_per_anteprima'); ?></p></div>
</article>
<?php endforeach; ?>
</div>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
If I change ids to $posts in the foreach it show me 1 result but without thumbnail and extra-fields.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.