I need to find comments posted in last 5 minutes. I am using the following query. What should be the value of before?

        $postID = get_the_ID();
            'date_query' => array(
                'after' => '5 minute ago',
                'before' => ?,
                'inclusive' => true,
            'post_id' => $postID,
            'status' => approve,  

Note that the function wp_list_comments() doesn't fetch the comments, only displays them in various ways depending on the input arguments.

You're actually using the WP_Comment_Query/get_comments input arguments into wp_list_comments().

You could try this instead:

$postID = 12345; // Adjust this!

$comments = get_comments( 
        'date_query' => [
            'after'     => '5 minutes ago',
            'inclusive' => true,
        'post_id' => $postID,
        'status'  => 'approve',  

     wp_list_comments( $args = [ 'echo' => 0 ], $comments )

where you can play with the comment output through the $args input array.

Check the Codex here.

Note that we can skip the before attribute when we use after attribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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