0

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' );

enter image description here

Sorry for My English.

3
0

The 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' ),
        ],
    ];
} );

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.