I need a query to show posts with same "publish date" as related posts. For Ex. if the post is published in 2012-08-02, i want to show other posts which are published in 2012-08-02 in bottom of the post. Is there any solution? Thank You.
I need a query to show posts with same "publish date" as related posts. For Ex. if the post is published in 2012-08-02, i want to show other posts which are published in 2012-08-02 in bottom of the post. Is there any solution? Thank You.
Share Improve this question asked Jan 31, 2020 at 14:57 Roshan NorouziRoshan Norouzi 111 bronze badge1 Answer
Reset to default 1Get the date of current post:
$date = get_the_date('Y-m-d');
Get year, month and day from the $date variable.
$exploded = explode('-', $date);
$year = $exploded[0];
$month = $exploded[1];
$day = $exploded[2];
Lastly, query the posts that has the same publish date.
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'date_query' => array(
array(
'year' => $year,
'month' => $month,
'day' => $day,
),
),
);
$query = new WP_Query( $args );
Add any query arguments and display the query results as you wish.