For a custom widget I want to retrieve the last posts published in the last hour.

All I can do actually is to display the posts of the day, with this query :

$queryArgs = array(
    'category_name' => 'myCategory',
    'posts_per_page'=> $number,
    'date_query' => array(
        array(
            'year' => date( 'Y' ),
            'month' => date( 'm' ),
            'day' => date( 'd' )
        ),
    ),
);
$query = new WP_Query($queryArgs);

1 Answer
1

You can try the following to query for last hour posts:

'date_query' => [
     [
         'after'     => '1 hour ago',  
         'inclusive' => true,
     ],
 ],

or

'date_query' => [
     [
         'after'     => 'last hour',  
         'inclusive' => true,
     ],
 ],

or

'date_query' => [
     [
         'after'     => '-1 hour',  
         'inclusive' => true,
     ],
 ],

Here we are playing with the strtotime() support in date_query.

Leave a Reply

Your email address will not be published. Required fields are marked *