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.
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.