Get previous posts list

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:

?php
$posts_args = array(
    'posts_per_page' = 10
  , 'meta_query'= array(
        array(
            'key'     = 'post_date'
          , 'compare' = ''
          , 'value'   = get_the_date('Y-m-d H:i:s')
        )
      )
);
$myposts = query_posts($posts_args);
?

Topic date previous comparison query Wordpress

Category Web


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(
        array(
            'before' => $date
        ),
    ),
    'posts_per_page' => 10,
);
$query = new WP_Query( $args );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.