• Hey there,

    I’ve been looking everywhere and I can’t believe I haven’t found it yet, don’t know what’s going wrong here.

    I got a single.php and I want to have an area with the two posts that were posted right before the current post.

    Say I have post 1-5, on single-1 I want to show posts 2&3, on single-3 I want to show posts 4&5. But it’s not working, it just shows the first two posts ever posted (so always 1&2). Can somebody tell me what’s wrong?

    $curTime = get_the_time("j F Y");
    $args = array(
    	'date_query' => array(
    		array(
    			'before'    => $curTime
    		),
    	),
    	'posts_per_page' => 2
    );
    $query = new WP_Query( $args );
    
    if ( $query->have_posts() ) {
    	while ( $query->have_posts() ) {
    		$query->the_post(); ?>
    <?php the_title(); ?>
     <?php } ?>
    		</div>
    	<?php	
    
    } else {
    }
    
    wp_reset_postdata();
    
    ?>

    Thank you for your help! ??

  • The topic ‘Showing two previous posts from current post on single.php’ is closed to new replies.