I created a custom field ACF named "date_dexpiration" with format : d/m/Y H:i
When I create a new post with no expiration date, the field "date_dexpiration" is not fullfilled and stays empty.
I want in an archive (created with elementor posts widget) set a custom filter in order to hide all the posts with a date "date_dexpiration" < today. I wrote this code inserted in function.php
add_action( 'elementor/query/filter_expiration_date', function( $query ) {
$today = date('d/m/Y H:i');
$meta_query = $query->get( 'meta_query' );
$meta_query = [
[
'key' => 'date_dexpiration',
'value' => $today,
'compare' => '>=',
]
];
$query->set( 'meta_query', $meta_query );
} );
It doesn't work:
- all the posts with empty field "date_dexpiration" aren't displayed
- all the field with filled field "date_dexpiration" aren't displayed
Can you help me please to debug this code.
ACF default format for date fields is
Ymd
so you need to convert$today
toYmd
format. Try this below code.