My code not work. How to correct code?
function filter_where( $where = '') {
$where .= " AND wp_comments.comment_date < '" . date('Y-m-d H:i:s') . "'";
}
add_filter( 'pre_get_comments', 'filter_where' );
Sorry for My English.
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityThe problem is you're not using the action hook at all in the proper way. You'll want to create date_query
parameters and add this to the comment query.
Here is what you can do to achieve this so that only comments created before "right now" are queried:
add_action( 'pre_get_comments', function ( $commentQuery ) {
$commentQuery->query_vars[ 'date_query' ] = [
[
'before' => current_time( 'mysql' ),
],
];
} );
return $where;