I have a custom post type where the posts have a start date and an end date. These are saved to the database as Unix timestamp/Epoch. I want to create a column for this custom post type called Active
where I want to show a green icon when the current date and time is between the start and end date.
How do I pull the metadata and compare them to the current date/time and if true display a green icon, if not a red icon?
I have this function which does almost the same thing but for search results. But I cannot figure out how to use this in a column:
function filter_search_results( $search_query ) {
$time = current_time( 'timestamp' );
if ( $search_query->is_search ) {
$search_query->set( 'meta_query', array(
'relation' => 'AND',
array(
'key' => 'visitor-start-date',
'value' => $time,
'compare' => '<='
),
array(
'key' => 'visitor-end-date',
'value' => $time,
'compare' => '>='
),
) );
}
}
add_action( 'pre_get_posts', 'filter_search_results' );