I have a custom post type which I can set a start and end date in the metadata.
I use the function below to filter the search results and only show results from the post type visitor
:
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'visitor');
}
return $query;
}
add_filter('pre_get_posts', 'SearchFilter');
I have two metadata fields that contains a start date and an end date:
get_post_meta( get_the_ID(), 'visitor-start-date', true ); // Start date
get_post_meta( get_the_ID(), 'visitor-date', true ); // End date
I want to filter the search results to only show results if the current date (today) is between these two dates.
The dates are in epoch/unix
and looks like this: 1539129600
1546214400
How do I include this in my filter I created above to only show results where todays date is between the start and end date?