1

How do I display posts by a specific date? If it is 15 July today, it'll display posts from about two or three days ago, like the 12th of July's posts. And tomorrow it'll display the 13th of July's post.

How can I achieve this?

1
  • Have a look at the custom date query parameters in WP_Query Commented Jul 16, 2014 at 13:10

1 Answer 1

2

I think if you want to show recent posts posted 2-3 days ago, you can use date queries, provided by WordPress

You can get more information about date queries from here: WordPress Date Queries

For Example: If you want to show last three days posts, it can be done using the following snippet of code:

//set the arguments
$args = array(
    'order' => 'DESC',
    'date_query' => array(
        array(
            'after' => '3 days ago',
        ),
    ),
);

// get posts using the arguments
$posts = get_posts($args);

The above will return an array of posts from last 3 days to the current day. You can also use it like: 3 days ago, 1 week ago etc.

3
  • Please indent your code properly before adding it to your question, it is hard to read. And please use proper syntax Commented Jul 16, 2014 at 16:52
  • hey thanx, but i need to show only one image with title something like 11th july on the archive page if someone clicks on the 11th july link then it will show all the images from 11th july.. how can i do this?
    – Code Smith
    Commented Jul 19, 2014 at 6:18
  • Then the following link will help you: link
    – Domain
    Commented Jul 19, 2014 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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