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?

    $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>
        <?php endforeach; ?>
        <?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.