Support

Account

Home Forums Backend Issues (wp-admin) Query only shows 1 result – the most recent. How can I get it to show ALL posts? Reply To: Query only shows 1 result – the most recent. How can I get it to show ALL posts?

  • Hi @lowercase

    I believe it was because you used the $posts variable multiple times before the loop is finished. Could you please try the following code instead?

    <?php 
       $posts = get_posts(array(
       'post_type'		=> 'videos',
       'posts_per_page' 	=> -1
             ));     
       if( $posts ): ?>
    <?php foreach( $posts as $post ): 
       setup_postdata( $post );            
       ?>
    <?php echo wp_oembed_get( get_field( 'video_youtube_url' ) ); ?>
    <h1 class="title"><?php the_title(); ?></h1>
    <?php 
       $posts2 = get_field('video_artist_name');            
       if( $posts2 ): ?>
    <?php foreach( $posts2 as $post): ?>
    <?php setup_postdata($post); ?>
    <a href="<?php the_permalink(); ?>">
       <div class="artist-name"><?php the_title(); ?></div>
    </a>
    <?php endforeach; ?>
    <?php wp_reset_postdata(); ?>
    <?php endif; ?>
    <?php endforeach; ?>
    <?php wp_reset_postdata(); ?>
    <?php endif; ?>

    I hope this helps.