I've done my hour+ research to find any answer but cannot find a solution.
Anyways... I have a wordpress posts page and on individual posts I have a query to display the latest 4 posts at the bottom of each post page.
What I'd like to do is only show 4 posts that are older than the current post page a visitor is on. Currently it shows the latest 4 entries no matter which post you're viewing.
Thank you.
<ul>
<?php $the_query = new WP_Query( array (
'post__not_in' => array( $post->ID ),
'posts_per_page' => 4,
'ignore_sticky_posts' => 1
) ); ?>
<div class="row">
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<li class="col-xs-12 col-md-3">
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute();
?>">
<?php the_post_thumbnail( 'post-thumbnail', ['class' => 'img-responsive
responsive--full'] ); ?>
</a>
<?php endif; ?>
<a href="<?php the_permalink() ?>"><p><?php the_title(); ?></p></a>
</li>
<?php
endwhile;
wp_reset_postdata();
?>
</div>
</ul>
You can use get_previous_post() to get the previous post. use this in a loop (assuming $post variable is updated for every post) to get previous 4 posts.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.