I'm creating a Custom Post for an event calendar. My Custom Post has 2 custom meta fields called "event_star_date" & "event_end_date". I want to use pre_get_posts
to exclude Events which their "event_end_date" is lower than todays date OR "event_end_date" is empty and "event_start_date" is lower than todays date. I have see some codes but the don't finaly work for me.
Thanks to @cybnet I have nearle get the code I need, but steel not working. What I would nedd could be something like this:
function bbwp_calendar_visible_events( $query ) {
if ( !is_admin() && $query->is_main_query() ){
if ( is_post_type_archive( $postType ) ) {
$meta_query = array(
'relation' => 'OR',
array(
'relation' => 'AND',
array(
'key' => 'event_start_date',
'value' => current_time( 'timestamp' ),
'type' => 'CHAR',
'compare' => '>=',
),
array(
'key' => 'event_end_date',
'value' => '',
'type' => 'CHAR',
'compare' => '=',
),
),
array(
'key' => 'event_end_date',
'value' => current_time( 'timestamp' ),
'type' => 'CHAR',
'compare' => '>=',
),
);
$query->set( 'meta_query', $meta_query );
}
}
}
add_action( 'pre_get_posts', 'bbwp_calendar_visible_events' );
Thanks to every body