Home › Forums › Front-end Issues › After upgrade post aggregator not working › Reply To: After upgrade post aggregator not working
I’ve replaced the code to have the new syntax as follows, but it still doesn’t show anthing in the events:
<h1>Upcoming Events at Lulu's Lounge</h1>
<div class="inner-box">
<?php
$today = current_time( 'timestamp' ); // Get current unix timestamp
$nextWeek = $today + (8 * 24 * 60 * 60);
$lulus = new WP_Query( array(
'post_type' => 'event',
'post_status' => 'publish',
'posts_per_page' => -1,
// 'orderby' => 'date',
// 'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_venue',
'value' => array('Lulus')
)
)
) );
if ( $lulus->have_posts() ) :
$i = 0;
$events = array();
while ( have_rows('dates') ) : the_row();
if(get_sub_field('event_date')){
$post_id = get_the_ID(); // Set the current post ID
$event_date = get_sub_field('event_date');
$event_location = get_field('event_venue');
$permalink = get_permalink();
$thumbnail = get_the_post_thumbnail($post_id);
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'thumbnail');
$ticket = get_sub_field('event_ticket_link');
$price = get_field('event_price');
$title = get_the_title();
$terms = get_the_terms($post_id, 'genre');
$url = wp_get_attachment_image_src($id,'event-thumb', true);
if($event_date >= $today){
if(isset($events[$post_id])){
$events[$post_id]['dates'][] = $event_date;
if($event_date < $events[$post_id]['earliest_date']){
$events[$post_id]['earliest_date'] = $event_date;
}
}
else{
$events[$post_id] = array(
'title' => $title,
'permalink' => $permalink,
'thumb' => $thumbnail,
'thumbnail_src' => $thumbnail_src,
'price' => $price,
'ticket' => $ticket,
'dates' => array($event_date),
'earliest_date' => $event_date,
'terms' => $terms
);
}
}
$i++;
}
echo "<pre>";
echo "======== Start debugging the events variable ========";
print_r($events[$post_id]);
echo "======== End debugging the events variable ========";
echo "======== Start debugging the events date ========";
print_r(get_sub_field('event_date'));
echo "======== End debugging the events date ========";
echo "</pre>";
endwhile;
usort($events, function($a, $b) {
return $a['earliest_date'] - $b['earliest_date'];
});
$numEvents = count($events);
// echo $numEvents;
$counter = 0;
foreach($events as $event) {
$permalink = $event['permalink'];
$title = $event['title'];
$thumb = $event['thumb'];
$thumbnail_src = $event['thumbnail_src'];
$ticket = $event['ticket'];
$terms = $event['terms'];
if($counter <= 24){ ?>
<div class="event-fifty <?php echo 'counter'.$counter; ?>">
<div class="newImageBox" style="background:url(<?php echo $thumbnail_src[0]; ?>);background-size:cover;background-position:center center;"></div>
<div class="lulu-text">
<h5><?php print $title; ?></h5>
<?php
// $terms = get_the_terms( $post->ID, 'genre' );
if ( $terms && ! is_wp_error( $terms ) ) :
$genres = array();
foreach ( $terms as $term ) {
$genres[] = $term->name;
}
$genre = join( " / ", $genres );
?>
<p class="location">
<?php echo $event_location; ?>
</p>
<p class="genre">
<?php echo $genre; ?>
</p>
<?php endif; ?>
<span class="time">
<?php
$numDates = count($event['dates']);
// print $numDates . ' dates... ';
$i = 0;
$img = get_stylesheet_directory_uri();
foreach ($event['dates'] as $date){
if($numDates == 1){
$first_date = date('M. j', $date);
$first_date_day = date('l', $date);
if(date('i', $date) != '00'){
$new_time = date('g:ia', $date);
}else{
$new_time = date('g:ia', $date);
}
echo $first_date_day. '<br />' . $first_date . '<br>' .$new_time;
// echo date('ga', $date);
}else{
// more than 1 date
if($i == $numDates-1){
$first = date('F', $event['dates'][0]);
$last = date('F',$event['dates'][$i]);
if(date('i', $date) != '00'){
$new_time = date('g:ia', $date);
}else{
$new_time = date('g:ia', $date);
}
$firstDayName = date('l', $event['dates'][0]);
$lastDayName = date('l', $event['dates'][$i]);
// echo $firstDayName . ' & ' . $lastDayName;
// check if all show day names are the same or not + assign all days names to an array
$allDaysNames = array();
$sameDaysNames = True;
for ($x = 0; $x < $numDates; $x++) {
$allDaysNames[$x] = date('D', $event['dates'][$x]);
if ($x > 0){
if ($sameDaysNames == True && $allDaysNames[$x] == $allDaysNames[$x-1]){
$sameDaysNames = True;
}else{
$sameDaysNames = False;
}
}
}
if($last != $first){
// different months
if( $numDates > 2 ){
if ($sameDaysNames == True){ //if all show day names are the same
echo $firstDayName . 's <br>'; //echo just first day in plural
}else{
// echo all days
foreach ($allDaysNames as $e => $dayName){
echo $dayName;
if ($e != $numDates-1){
echo ", ";
}else{
echo "<br>";
}
}
}
//echo 'Starts ' . $firstDayName . '<br>';
}else{
if( $firstDayName == $lastDayName ) { // wednesday & wednesday
echo $firstDayName . 's <br>';
}else{
echo $firstDayName . ' & '. $lastDayName . '<br>';
}
}
//echo date('M. j -', $event['dates'][0]) . date('M. j, ', $event['dates'][$i]) . $new_time;
//echo "<br>";
$x_month = "a";
$current_month = "a";
for ($x = 0; $x < $numDates; $x++) {
$current_month = date('F', $event['dates'][$x]);
//echo $x_month . " | " . $current_month;
//echo "<br>";
if ($current_month != $x_month) {
if ($x > 0) {
echo " | ";
}
echo date('M. j', $event['dates'][$x]);
}else{
echo date(', j', $event['dates'][$x]);
}
$x_month = date('F', $event['dates'][$x]);
}
echo "<br>" . $new_time;
}else{
if( $numDates > 2 ){
if ($sameDaysNames == True){ //if all show day names are the same
echo $firstDayName . 's <br>'; //echo just first day in plural
}else{
// echo all days
foreach ($allDaysNames as $e => $dayName){
echo $dayName;
if ($e != $numDates-1){
echo ", ";
}else{
echo "<br>";
}
}
}
//echo 'Starts ' . $firstDayName . '<br>';
}else{
if( $firstDayName == $lastDayName ) { // wednesday & wednesday
echo $firstDayName . 's <br>';
}else{
echo $firstDayName . ' & '. $lastDayName . '<br>';
}
}
//echo date('M. j -', $event['dates'][0]). date('j, ', $event['dates'][$i]) . $new_time;
//echo "<br>";
for ($x = 0; $x < $numDates; $x++) {
if ($x == 0) {
echo date('M. j', $event['dates'][$x]);
}else{
echo date(', j', $event['dates'][$x]);
}
}
echo "<br>" . $new_time;
}
}
}
$i++;
}
?>
</span>
</div>
</div>
<?php if( ($counter == 4) || ($counter == 9) || ($counter == 14) || ($counter == 19) ){
// if( $counter == 4)|| ($counter == 9)|| ($counter == 14) || ($counter == 19) ) {
?>
<?php }; ?>
<?php if( ($counter == $numEvents-1) || ($counter == 24) ) { ?>
<?php }; ?>
<?php //}; ?>
<?php $counter++; ?>
<?php }; ?>
<?php }; // end foreach ?>
<?php endif; ?>
<?php
// echo "<pre>";
// var_dump($events);
// echo "</pre>";
?>
<?php wp_reset_postdata(); ?>
</div>
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.