Home › Forums › Add-ons › Repeater Field › Calendar by month with date repeater › Reply To: Calendar by month with date repeater
You need to use the $rows
variable that holds the wpdb result. Something like this:
$rows = $wpdb->get_results($wpdb->prepare(
"
SELECT *
FROM {$wpdb->prefix}postmeta
WHERE meta_key LIKE %s
",
'calendrier_%_jour_debut'
));
// vars
$order = array();
// populate order
foreach( $rows as $i => $row ) {
$order[ $i ] = $row['meta_value'];
}
// multisort
array_multisort( $order, SORT_ASC, $rows );
// Temporary month variable
$current_month = null;
// Loop through the returned rows
foreach( $rows as $row){
// Convert the date string to PHP datetime
$date = DateTime::createFromFormat('Ymd', $row['meta_value']);
// Get the month
$month = $date->format('F');
// Echo the months only once
if( $current_month != $month ){
echo $month . "\r\n";
$current_month = $month;
}
// Show the date string
echo $row['meta_value'] . "\r\n";
// Get the related post
$thepost = get_post($row['post_id']);
// Show it if you want
print_r($thepost);
// Get the event repeater for the related post
$calendrier = get_field('calendrier', $thepost->ID);
// Show it if you want
print_r($calendrier);
}
Hope this helps 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.