Friends, I ask for help in an unusual task.
Wordpress and a custom post type events. Events have several ACF fields: e_date (event date), e_active (true/false field - real event) and e_forecast (true/false field - event forecast). When filling in an event, e_date (a required field) is filled in and e_active or e_forecast is set, depending on the type of event. So, I need to get all the event records, check these records for compliance with certain rules and output one last record. The rules are as follows:
Check all entries with
e_activeby date. I.e. comparee_datewith the current date. If there is ane_activeevent and with ane_datethat has not yet occurred, then we output it.If all
e_activewithe_datehave passed, i.e. they do not correspond to point 1, then we checke_forecastande_dateaccording to the same principle.If 1 and 2 don't fit, then just
else {}
At the moment, I get 1 last published record, but often e_forecast is published later than e_active, although e_active has not yet reached e_date.
$events = get_posts([
'post_type' => 'events',
'numberposts' => 1,
'meta_query' => [
'relation' => 'OR',
[
'key' => 'e_active',
'value' => true
],
[
'key' => 'e_forecast',
'value' => true
]
]
]);
Unfortunately, I myself can't even imagine how to sort through, say, the last 10 records for compliance with the described rules. I really hope your help)