I'll give up. Have searched and searched and tried and tried... Can't find any solution to list previous posts.

On a single post: I want to show a list of the 10 previous posts, the 10 before the current post. So, not just a two prev and next links. Not the most recent posts that is. A list of the the 10 previous posts before the current post you are visiting.

I'm trying to make a query and comparing post_date lower than get_the_date('Y-m-d H:i:s'). But it's not working. I guess post_date isn't an allowed key to use in 'compare'.

Any ideas?

Edit: The code right now:

$posts_args = array(
    'posts_per_page' => 10
  , 'meta_query'=> array(
            'key'     => 'post_date'
          , 'compare' => '<'
          , 'value'   => get_the_date('Y-m-d H:i:s')
$myposts = query_posts($posts_args);
  • Please post all of your relevant code. – s_ha_dum Nov 15 '15 at 23:32
  • I change it continuously cause I'm testing different things. But look at my edit now. – Peter Westerlund Nov 15 '15 at 23:41

Did you chceck the Codex Date Parameters ? Expecially the 'before' param.
It works like this:

$date = get_the_date('Y-m-d H:i:s');
$args = array(
    'date_query' => array(
            'before' => $date
    'posts_per_page' => 10,
$query = new WP_Query( $args );
| improve this answer | |
  • Strange. Some how, this code makes the page doing an redirection to the "Hello world" (first) post. – Peter Westerlund Nov 16 '15 at 0:13
  • Aha, I needed <?php wp_reset_postdata(); ?> – Peter Westerlund Nov 16 '15 at 0:36

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.