I’m working with an external database in WordPress and trying to use an IF statement if a column has a certain value. So the column ‘period’ will have the value of either ‘week’, ‘month’ or ‘year’. I want to be able to change the data based on that. Am I headed in the right direction? Any help appreciated.
$recurring_events = $events_db->get_results(
"
SELECT gc_event_id, period
FROM gc_event_recurring
WHERE gc_event_id = '$masterID'
"
);
foreach ($recurring_events as $recurring_event) :
if ($recurring_events['period'] === 'month') { <-- NEED HELP HERE
// Do Something
} else if ($recurring_events['period'] === 'year') {
// Do Something
}
By default,
get_resultsreturns objects instead of arrays. It also looks like you’re referencing$recurring_eventswhere you should be referencing$recurring_event.Try using this line instead within the foreach, where you said you need help: