I want to get all post which was posted on X Days, I don't want 7 days old post or 1 Month old posts, Because it will return all posts which will be older 7 days or one month. Like Today is 15 SEP, I want to get all posts which was post on 5 SEP. Only 5 sep not older then 5 SEP. Only one Day posts. I have try code like this
$args = array(
'posts_per_page' => -1,
'post_type' => 'post',
'date_query' => array(
'after' => date('Y-m-d', strtotime('-10 days'))
)
);
But its return 10 days old posts. Any help to get post for X days?
I want to get all post which was posted on X Days, I don't want 7 days old post or 1 Month old posts, Because it will return all posts which will be older 7 days or one month. Like Today is 15 SEP, I want to get all posts which was post on 5 SEP. Only 5 sep not older then 5 SEP. Only one Day posts. I have try code like this
$args = array(
'posts_per_page' => -1,
'post_type' => 'post',
'date_query' => array(
'after' => date('Y-m-d', strtotime('-10 days'))
)
);
But its return 10 days old posts. Any help to get post for X days?
You can use 'date_query' to achieve exactly what you need. All you have to do is not to use 'before' or 'after', but only date (the way WordPress does when you go to day archive).
Here’s the code you can use:
$date = strtotime('-10 days');
$args = array(
'posts_per_page' => -1,
'post_type' => 'post',
'date_query' => array(
array(
'year' => date('Y', $date),
'month' => date('m', $date),
'day' => date('d', $date),
),
),
);
$posts= new WP_Query( $args );
You can try following code
$y = date('Y');
$m = date('m');
$d = date('d',strtotime("-7 days")); //Date you want
$args = array(
'posts_per_page' => -1,
'post_type' => 'post',
'date_query' => array(
array(
'year' => $y,
'month' => $m,
'day' => $d,
),
),
);
$posts= new WP_Query( $args ); //you will get posts which are posted on specific date