I’m trying to create a function to populate an ajax calendar with events.
I’m querying a date (format Ymd) from custom field in my wordpress database.
$metakey2 = 'jour';
$jours = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey2) );
if ($jours) {
$years = substr($jours, 0, 4); // OUTPUT YEAR FROM DATE
$months = substr($jours, 5, 2); // OUTPUT MONTH FROM DATE
$days = substr($jours, 7, 2); // OUTPUT DAY FROM DATE
foreach $years as $year {
foreach $months as $month {
if ($y == $year AND $m == $month) {
$events = array(
foreach $days as $day {
$day => array(
0 => array(
"0" => "Lorem ipsum dolor 111",
)
);
}
);
}
}
}
}
`
I’m definitely no expert and I’ve been trying to make this work for hours now… Can someone point me towards the right direction please?
Thank you,
Manue
The key is the foreach loop after the empty check. You need to loop through the data that is returned from the db as an array.