I'm trying to hide all posts with past date(which is a custom field). I'm doing it with pre_get_posts, but no matter what I do, all pages become 404 not found, and I can't find the problem. Here is the function:
function hide_past_events( $query ) {
if ( !$query->is_main_query() || is_admin() ) {
return;
}
$meta_query = (array)$query->get('meta_query');
$meta_query[] = [
[
'key' => '_the_custom_field',
'value' => time(),
'compare' => '>'
]
];
$query->set( 'meta_query', $meta_query );
}
add_filter( 'pre_get_posts', 'hide_past_events' );