最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - Add to previous posts under post

matteradmin5PV0评论

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?

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?

Share Improve this question edited Mar 20, 2019 at 18:26 Qaisar Feroz 2,1471 gold badge9 silver badges20 bronze badges asked Mar 20, 2019 at 14:54 MantaRayMantaRay 254 bronze badges 1
  • WP_Query Date Parameters – Max Yudin Commented Mar 20, 2019 at 15:04
Add a comment  | 

1 Answer 1

Reset to default 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,
                                 ),
                            ),

              ));

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far