• It would be nice if there was a setting that would automatically disable comments on older events. I tried the WordPress setting to disable comments after 14-days but that doesn’t seem to work in events. I have occasional trouble with spammers finding open comments in old events.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Add the following code snippet to disable comments on events that ended more than 14 days ago.

    add_filter( 'comments_open', 'disable_comments_on_expired_events', 10, 2 );

    function disable_comments_on_expired_events( $open, $post_id ) {
    $post = get_post( $post_id );

    // Only apply to the "event" post type
    if ( $post->post_type !== 'event' ) {
    return $open;
    }

    /**
    * key: '_event_end_date' (Events Manager)
    */
    $end_date_raw = get_post_meta( $post_id, '_event_end_date', true );

    if ( $end_date_raw ) {
    $end_timestamp = strtotime( $end_date_raw );
    $fourteen_days_ago = strtotime( '-14 days' );

    // If the event ended more than 14 days before today, close comments
    if ( $end_timestamp < $fourteen_days_ago ) {
    return false;
    }
    }

    return $open;
    }

    You can use the Code Snippets plugin to add this code snippet.

    Thread Starter grezes71

    (@grezes71)

    Thank you! I’ll give that a try.

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.