0

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' );
CritingZ
  • 388
  • 2
  • 16

1 Answers1

0

I'm using 'the_posts' filter hook to find posts that does not fit my requirements and replace it with another.