0

Goal: After each post (that contains under a certain amount of words), display the two posts that were published before it in that category/tab.

I found this on stack, where they do something similar, but they're displaying the 2 most recent posts. I want to display the 2 that were published before the currently-read article, though. Is there a way to modify this code?

1

Try to add date_query to the $qry in the solution mentioned here.

$qry = new WP_Query(
       array(
            'cat'            => $current_post_categories[0],
            'posts_per_page' => 2,
            'post__not_in'   => array( $current_post_id ),

            'date_query' => array(
                                 array(
                                     'before'     => $post->post_date,
                                 ),
                            ),

              ));
  • Thanks! This seems to be working correctly! If I find I'm wrong about that, I'll edit this comment. Great! – MantaRay Mar 20 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.