• Resolved neilsavage

    (@neilsavage)


    I am working on creating an agenda that shows recurring events, very similar to your case. I used the function from one of the other threads to query and sort the events but am having trouble listing the events.

    Currently this is in my functions.php file

    function my_post_saved($post_id)
    {
        if (!$post_id || get_post_type($post_id) !== 'event') {
            return;
        }
    
        $rrule = get_field('recurring_dates', $post_id);
    
        // Update start and end dates in post meta
        update_post_meta($post_id, 'start_date', $rrule['start_date']);
        update_post_meta($post_id, 'end_date', $rrule['end_date']);
    }
    add_action('acf/save_post', 'my_post_saved');
    
    /**
     * Get all events between two dates.
     *
     * @param  mixed $start
     * @param  mixed $end
     * @return array
     */
    function fbdm_get_events($start = null, $end = null, $data = [])
    {
        $events = [];
        $has_more = false;
        $index = 0;
    
        if (! $start) {
            // Defaults to today
            $start = new DateTime();
        } elseif (! $start instanceof DateTime) {
            $start = DateTime::createFromFormat('Y-m-d', $start);
        }
    
        if (! $end) {
            // Defaults to start date + 1 month
            $end = clone $start;
            $end->add(new DateInterval('P1M'));
        } elseif (! $end instanceof DateTime) {
            $end = DateTime::createFromFormat('Y-m-d', $end);
        }
    
        $start->setTime(0,0,0);
        $end->setTime(0,0,0);
    
        // Break the loop after 14 events
        while (sizeof($events) <= 14) {
            if ($index > 0) {
                $start = clone $end;
                $start->add(new DateInterval('P1D'));
    
                $end = clone $start;
                $end->add(new DateInterval('P1M'));
            }
    
            // Query all events which have not ended at start date
            $args = [
                'post_type' => 'event',
                'posts_per_page' => -1,
                'post_status' => 'publish',
                'meta_query' => [
                    'relation' => 'AND',
                    [
                        'key' => 'end_date',
                        'compare' => '>=',
                        'value' => $start->format('Y-m-d'),
                        'type' => 'DATE',
                    ],
                ],
            ];
    
            $query = new WP_Query($args);
    
            // Count posts from start date
            if (! count($query->get_posts())) {
                $has_more = false;
                break;
            }
    
            // Add end date to query arguments
            $args['meta_query'][] = [
                'key' => 'start_date',
                'compare' => '<=',
                'value' => $end->format('Y-m-d'),
                'type' => 'DATE',
            ];
    
            $query = new WP_Query($args);
    
            foreach ($query->get_posts() as $post) {
                $post->dates = fbdm_get_event_dates($post->ID);
    
                foreach ($post->dates as $date => $array) {
                    $datetime = new DateTime($date);
    
                    if ($datetime < $start) {
                        continue;
                    } elseif ($end && $datetime > $end) {
                        $has_more = true;
                        break;
                    }
    
                    // Push the event to the array of dates
                    if (! array_key_exists($date, $events)) {
                        $timestamp = $datetime->getTimestamp() + $datetime->getOffset();
    
                        $day = date_i18n("l j F", $timestamp);
    
                        $events[$date] = [
                            'day' => $day,
                            'month' => date_i18n("F Y", $timestamp),
                            'events' => [],
                        ];
                    }
    
                    foreach ($array as $time) {
                        $time_full = $time['start_time'];
    
                        if ($time['end_time']) {
                            $time_full .= "-{$time['end_time']}";
                        }
    
                        // Update an existing row
                        if (array_key_exists($post->ID, $events[$date]['events'])) {
                            $events[$date]['events'][$post->ID]['time'][] = $time_full;
    
                            sort($events[$date]['events'][$post->ID]['time']);
                        }
                        // Create a new row
                        else {
                            $events[$date]['events'][$post->ID] = [
                                'post' => $post,
                                'start_time' => $time['start_time'],
                                'end_time' => $time['end_time'],
                                'time' => [$time_full],
                            ];
                        }
                    }
    
                    // Sort events by start time
                    usort($events[$date]['events'], function($a, $b) {
                        return $a['start_time'] <=> $b['start_time'];
                    });
                }
            }
    
            if ($index++ > 3) {
                break;
            }
        }
    
        // Sort events array by date (key)
        ksort($events);
    
        return [
            'events' => $events,
            'has_more' => $has_more
        ];
    }
    
    /**
     * Get all dates for an event.
     *
     * @param  int $post_id
     * @return array
     */
    function fbdm_get_event_dates( $post_id )
    {
        if (! $post_id || get_post_type($post_id) !== 'event') {
            return;
        }
    
        $dates = [];
    
        $recurrence = get_field('recurring_dates');
    
        foreach ($recurrence['dates_collection'] as $date) {
            if (! array_key_exists($date->format('Y-m-d'), $dates)) {
                $dates[$date->format('Y-m-d')] = [];
            }
    
            // I created two ACF time fields along with the RRule field 
            // to set the start and end times of each occurrence.
            // If you don't need to specify the times for your occurrences
            // you can just push the date to the array instead of using key => value
            $dates[$date->format('Y-m-d')][] = [
                'start_time' => get_field('event_start_time'),
                'end_time' => get_field('event_end_time'),
            ];
        }
    
        // Sort dates
        ksort($dates);
    
        return $dates;
    }

    I want to display the event on the custom post type archive page in which I’m calling the function then trying to loop the dates, but I’m getting the wrong dates and too many events at once. Here is what I have:

    <?php 
    
    				// Call the function to retrieve events
    				$events_data = fbdm_get_events(); // Limit to 14 posts initially
    
    				// Check if events are available
    				if (!empty($events_data['events'])) {
    				    $events = $events_data['events'];
    
    				    $eventstest = $event['events'];
    
    				    var_dump($eventstest);
    
    				    // Loop through each event date
    				    foreach ($events as $date => $event) {
    				        // Loop through events for this date
    				        foreach ($event['events'] as $event_data) {
    				            // Access event details and display them in individual containers
    				            $post = $event_data['post'];
    				            $start_time = $event_data['start_time'];
    				            $end_time = $event_data['end_time'];
    				            $event_date = $event['day'] ?? ''; // Assuming 'day' holds the date
    
    				            // Get the permalink for the event
    				            $permalink = get_permalink($post->ID);
    
    				            // Wrap the event container with the permalink
    				            echo '<div class="event-container cell small-12">';
    				            echo '<a href="' . esc_url($permalink) . '" class="event-link">';
    				            echo '<h3>' . $post->post_title . '</h3>';
    				            echo '<p>Date: ' . $event_date . '</p>';
    				            echo '<p>Start Time: ' . $start_time . '</p>';
    				            echo '<p>End Time: ' . $end_time . '</p>';
    				            echo '</a>';
    				            // Display more event details as needed
    				            echo '</div>';
    				        }
    				    }
    
    				    // Check if there are more events to load
    				    $has_more = $events_data['has_more'];
    
    				    // Display Load More button if there are more events
    				    if ($has_more) {
    				        echo '<button id="load-more-events">Load More</button>';
    				    }
    				} else {
    				    // Handle case where no events are found
    				    echo '<p>No events found.</p>';
    				}
    
    				?>

    Am I on the right track? I feel like I’m having trouble with the data. Thank you in advanced

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Marc Bellêtre

    (@marcbelletre)

    Hi @neilsavage,

    The goal of this plugin is to provide a field that can save recurring dates in database. The way you use them in custom queries is totally up to you.

    Without more context it is hard to tell what is going on with your code.

    You said that the second piece of code that loops through the date is used in a post archive template. If it is used inside the main have_posts() loop it will be executed multiple times so you will get the same list of posts for as many post in the loop. The fbdm_get_events function shoud be called only once.

    Thread Starter neilsavage

    (@neilsavage)

    Thanks Marc,

    I appreciate you helping with this. I tried running the fbdm_get_events() function on a single post – outside of any loops. The array I get back doesn’t look right:

    array(2) {
      ["events"] => array(3) {
        ["2023-12-13"] => array(3) {
          ["day"] => string(21)
          "Wednesday 13 December" ["month"] => string(13)
          "December 2023" ["events"] => array(2) {
            [0] => array(4) {
              ["post"] => object(WP_Post) #2088 (25) { ["ID"]= > int(47)["post_author"] => string(1)
              "1" ["post_date"] => string(19)
              "2023-12-11 16:54:13" ["post_date_gmt"] => string(19)
              "2023-12-11 21:54:13" ["post_content"] => string(0)
              "" ["post_title"] => string(17)
              "Whiskey Wednesday" ["post_excerpt"] => string(0)
              "" ["post_status"] => string(7)
              "publish" ["comment_status"] => string(4)
              "open" ["ping_status"] => string(4)
              "open" ["post_password"] => string(0)
              "" ["post_name"] => string(17)
              "whiskey-wednesday" ["to_ping"] => string(0)
              "" ["pinged"] => string(0)
              "" ["post_modified"] => string(19)
              "2023-12-13 13:15:37" ["post_modified_gmt"] => string(19)
              "2023-12-13 18:15:37" ["post_content_filtered"] => string(0)
              "" ["post_parent"] => int(0)["guid"] => string(69)
              "?post_type=event&p=47" ["menu_order"] => int(0)["post_type"] => string(5)
              "event" ["post_mime_type"] => string(0)
              "" ["comment_count"] => string(1)
              "0" ["filter"] => string(3)
              "raw" ["dates"] => array(6) {
                ["2023-11-22"] => array(1) {
                  [0] => array(2) {
                    ["start_time"] => string(8)
                    "10:00 am" ["end_time"] => string(7)
                    "6:00 pm"
                  }
                } ["2023-11-29"] => array(1) {
                  [0] => array(2) {
                    ["start_time"] => string(8)
                    "10:00 am" ["end_time"] => string(7)
                    "6:00 pm"
                  }
                } ["2023-12-06"] => array(1) {
                  [0] => array(2) {
                    ["start_time"] => string(8)
                    "10:00 am" ["end_time"] => string(7)
                    "6:00 pm"
                  }
                } ["2023-12-13"] => array(1) {
                  [0] => array(2) {
                    ["start_time"] => string(8)
                    "10:00 am" ["end_time"] => string(7)
                    "6:00 pm"
                  }
                } ["2023-12-20"] => array(1) {
                  [0] => array(2) {
                    ["start_time"] => string(8)
                    "10:00 am" ["end_time"] => string(7)
                    "6:00 pm"
                  }
                } ["2023-12-27"] => array(1) {
                  [0] => array(2) {
                    ["start_time"] => string(8)
                    "10:00 am" ["end_time"] => string(7)
                    "6:00 pm"
                  }
                }
              }
            } ["start_time"] => string(8)
            "10:00 am" ["end_time"] => string(7)
            "6:00 pm" ["time"] => array(1) {
              [0] => string(16)
              "10:00 am-6:00 pm"
            }
          } [1] => array(4) {
            ["post"] => object(WP_Post) #2083 (25) { ["ID"]= > int(46)["post_author"] => string(1)
            "1" ["post_date"] => string(19)
            "2023-12-11 16:09:41" ["post_date_gmt"] => string(19)
            "2023-12-11 21:09:41" ["post_content"] => string(0)
            "" ["post_title"] => string(16)
            "Friday Recurring" ["post_excerpt"] => string(0)
            "" ["post_status"] => string(7)
            "publish" ["comment_status"] => string(4)
            "open" ["ping_status"] => string(4)
            "open" ["post_password"] => string(0)
            "" ["post_name"] => string(16)
            "friday-recurring" ["to_ping"] => string(0)
            "" ["pinged"] => string(0)
            "" ["post_modified"] => string(19)
            "2023-12-13 13:16:49" ["post_modified_gmt"] => string(19)
            "2023-12-13 18:16:49" ["post_content_filtered"] => string(0)
            "" ["post_parent"] => int(0)["guid"] => string(69)
            "?post_type=event&p=46" ["menu_order"] => int(0)["post_type"] => string(5)
            "event" ["post_mime_type"] => string(0)
            "" ["comment_count"] => string(1)
            "0" ["filter"] => string(3)
            "raw" ["dates"] => array(6) {
              ["2023-11-22"] => array(1) {
                [0] => array(2) {
                  ["start_time"] => string(8)
                  "10:00 am" ["end_time"] => string(7)
                  "6:00 pm"
                }
              } ["2023-11-29"] => array(1) {
                [0] => array(2) {
                  ["start_time"] => string(8)
                  "10:00 am" ["end_time"] => string(7)
                  "6:00 pm"
                }
              } ["2023-12-06"] => array(1) {
                [0] => array(2) {
                  ["start_time"] => string(8)
                  "10:00 am" ["end_time"] => string(7)
                  "6:00 pm"
                }
              } ["2023-12-13"] => array(1) {
                [0] => array(2) {
                  ["start_time"] => string(8)
                  "10:00 am" ["end_time"] => string(7)
                  "6:00 pm"
                }
              } ["2023-12-20"] => array(1) {
                [0] => array(2) {
                  ["start_time"] => string(8)
                  "10:00 am" ["end_time"] => string(7)
                  "6:00 pm"
                }
              } ["2023-12-27"] => array(1) {
                [0] => array(2) {
                  ["start_time"] => string(8)
                  "10:00 am" ["end_time"] => string(7)
                  "6:00 pm"
                }
              }
            }
          } ["start_time"] => string(8)
          "10:00 am" ["end_time"] => string(7)
          "6:00 pm" ["time"] => array(1) {
            [0] => string(16)
            "10:00 am-6:00 pm"
          }
        }
      }
    } ["2023-12-20"] => array(3) {
      ["day"] => string(21)
      "Wednesday 20 December" ["month"] => string(13)
      "December 2023" ["events"] => array(2) {
        [0] => array(4) {
          ["post"] => object(WP_Post) #2088 (25) { ["ID"]= > int(47)["post_author"] => string(1)
          "1" ["post_date"] => string(19)
          "2023-12-11 16:54:13" ["post_date_gmt"] => string(19)
          "2023-12-11 21:54:13" ["post_content"] => string(0)
          "" ["post_title"] => string(17)
          "Whiskey Wednesday" ["post_excerpt"] => string(0)
          "" ["post_status"] => string(7)
          "publish" ["comment_status"] => string(4)
          "open" ["ping_status"] => string(4)
          "open" ["post_password"] => string(0)
          "" ["post_name"] => string(17)
          "whiskey-wednesday" ["to_ping"] => string(0)
          "" ["pinged"] => string(0)
          "" ["post_modified"] => string(19)
          "2023-12-13 13:15:37" ["post_modified_gmt"] => string(19)
          "2023-12-13 18:15:37" ["post_content_filtered"] => string(0)
          "" ["post_parent"] => int(0)["guid"] => string(69)
          "https://peabodyheights.wpenginepowered.com/?post_type=event&p=47" ["menu_order"] => int(0)["post_type"] => string(5)
          "event" ["post_mime_type"] => string(0)
          "" ["comment_count"] => string(1)
          "0" ["filter"] => string(3)
          "raw" ["dates"] => array(6) {
            ["2023-11-22"] => array(1) {
              [0] => array(2) {
                ["start_time"] => string(8)
                "10:00 am" ["end_time"] => string(7)
                "6:00 pm"
              }
            } ["2023-11-29"] => array(1) {
              [0] => array(2) {
                ["start_time"] => string(8)
                "10:00 am" ["end_time"] => string(7)
                "6:00 pm"
              }
            } ["2023-12-06"] => array(1) {
              [0] => array(2) {
                ["start_time"] => string(8)
                "10:00 am" ["end_time"] => string(7)
                "6:00 pm"
              }
            } ["2023-12-13"] => array(1) {
              [0] => array(2) {
                ["start_time"] => string(8)
                "10:00 am" ["end_time"] => string(7)
                "6:00 pm"
              }
            } ["2023-12-20"] => array(1) {
              [0] => array(2) {
                ["start_time"] => string(8)
                "10:00 am" ["end_time"] => string(7)
                "6:00 pm"
              }
            } ["2023-12-27"] => array(1) {
              [0] => array(2) {
                ["start_time"] => string(8)
                "10:00 am" ["end_time"] => string(7)
                "6:00 pm"
              }
            }
          }
        } ["start_time"] => string(8)
        "10:00 am" ["end_time"] => string(7)
        "6:00 pm" ["time"] => array(1) {
          [0] => string(16)
          "10:00 am-6:00 pm"
        }
      } [1] => array(4) {
        ["post"] => object(WP_Post) #2083 (25) { ["ID"]= > int(46)["post_author"] => string(1)
        "1" ["post_date"] => string(19)
        "2023-12-11 16:09:41" ["post_date_gmt"] => string(19)
        "2023-12-11 21:09:41" ["post_content"] => string(0)
        "" ["post_title"] => string(16)
        "Friday Recurring" ["post_excerpt"] => string(0)
        "" ["post_status"] => string(7)
        "publish" ["comment_status"] => string(4)
        "open" ["ping_status"] => string(4)
        "open" ["post_password"] => string(0)
        "" ["post_name"] => string(16)
        "friday-recurring" ["to_ping"] => string(0)
        "" ["pinged"] => string(0)
        "" ["post_modified"] => string(19)
        "2023-12-13 13:16:49" ["post_modified_gmt"] => string(19)
        "2023-12-13 18:16:49" ["post_content_filtered"] => string(0)
        "" ["post_parent"] => int(0)["guid"] => string(69)
        "?post_type=event&p=46" ["menu_order"] => int(0)["post_type"] => string(5)
        "event" ["post_mime_type"] => string(0)
        "" ["comment_count"] => string(1)
        "0" ["filter"] => string(3)
        "raw" ["dates"] => array(6) {
          ["2023-11-22"] => array(1) {
            [0] => array(2) {
              ["start_time"] => string(8)
              "10:00 am" ["end_time"] => string(7)
              "6:00 pm"
            }
          } ["2023-11-29"] => array(1) {
            [0] => array(2) {
              ["start_time"] => string(8)
              "10:00 am" ["end_time"] => string(7)
              "6:00 pm"
            }
          } ["2023-12-06"] => array(1) {
            [0] => array(2) {
              ["start_time"] => string(8)
              "10:00 am" ["end_time"] => string(7)
              "6:00 pm"
            }
          } ["2023-12-13"] => array(1) {
            [0] => array(2) {
              ["start_time"] => string(8)
              "10:00 am" ["end_time"] => string(7)
              "6:00 pm"
            }
          } ["2023-12-20"] => array(1) {
            [0] => array(2) {
              ["start_time"] => string(8)
              "10:00 am" ["end_time"] => string(7)
              "6:00 pm"
            }
          } ["2023-12-27"] => array(1) {
            [0] => array(2) {
              ["start_time"] => string(8)
              "10:00 am" ["end_time"] => string(7)
              "6:00 pm"
            }
          }
        }
      } ["start_time"] => string(8)
      "10:00 am" ["end_time"] => string(7)
      "6:00 pm" ["time"] => array(1) {
        [0] => string(16)
        "10:00 am-6:00 pm"
      }
    }
    }
    } ["2023-12-27"] => array(3) {
      ["day"] => string(21)
      "Wednesday 27 December" ["month"] => string(13)
      "December 2023" ["events"] => array(2) {
        [0] => array(4) {
          ["post"] => object(WP_Post) #2088 (25) { ["ID"]= > int(47)["post_author"] => string(1)
          "1" ["post_date"] => string(19)
          "2023-12-11 16:54:13" ["post_date_gmt"] => string(19)
          "2023-12-11 21:54:13" ["post_content"] => string(0)
          "" ["post_title"] => string(17)
          "Whiskey Wednesday" ["post_excerpt"] => string(0)
          "" ["post_status"] => string(7)
          "publish" ["comment_status"] => string(4)
          "open" ["ping_status"] => string(4)
          "open" ["post_password"] => string(0)
          "" ["post_name"] => string(17)
          "whiskey-wednesday" ["to_ping"] => string(0)
          "" ["pinged"] => string(0)
          "" ["post_modified"] => string(19)
          "2023-12-13 13:15:37" ["post_modified_gmt"] => string(19)
          "2023-12-13 18:15:37" ["post_content_filtered"] => string(0)
          "" ["post_parent"] => int(0)["guid"] => string(69)
          "https://peabodyheights.wpenginepowered.com/?post_type=event&p=47" ["menu_order"] => int(0)["post_type"] => string(5)
          "event" ["post_mime_type"] => string(0)
          "" ["comment_count"] => string(1)
          "0" ["filter"] => string(3)
          "raw" ["dates"] => array(6) {
            ["2023-11-22"] => array(1) {
              [0] => array(2) {
                ["start_time"] => string(8)
                "10:00 am" ["end_time"] => string(7)
                "6:00 pm"
              }
            } ["2023-11-29"] => array(1) {
              [0] => array(2) {
                ["start_time"] => string(8)
                "10:00 am" ["end_time"] => string(7)
                "6:00 pm"
              }
            } ["2023-12-06"] => array(1) {
              [0] => array(2) {
                ["start_time"] => string(8)
                "10:00 am" ["end_time"] => string(7)
                "6:00 pm"
              }
            } ["2023-12-13"] => array(1) {
              [0] => array(2) {
                ["start_time"] => string(8)
                "10:00 am" ["end_time"] => string(7)
                "6:00 pm"
              }
            } ["2023-12-20"] => array(1) {
              [0] => array(2) {
                ["start_time"] => string(8)
                "10:00 am" ["end_time"] => string(7)
                "6:00 pm"
              }
            } ["2023-12-27"] => array(1) {
              [0] => array(2) {
                ["start_time"] => string(8)
                "10:00 am" ["end_time"] => string(7)
                "6:00 pm"
              }
            }
          }
        } ["start_time"] => string(8)
        "10:00 am" ["end_time"] => string(7)
        "6:00 pm" ["time"] => array(1) {
          [0] => string(16)
          "10:00 am-6:00 pm"
        }
      } [1] => array(4) {
        ["post"] => object(WP_Post) #2083 (25) { ["ID"]= > int(46)["post_author"] => string(1)
        "1" ["post_date"] => string(19)
        "2023-12-11 16:09:41" ["post_date_gmt"] => string(19)
        "2023-12-11 21:09:41" ["post_content"] => string(0)
        "" ["post_title"] => string(16)
        "Friday Recurring" ["post_excerpt"] => string(0)
        "" ["post_status"] => string(7)
        "publish" ["comment_status"] => string(4)
        "open" ["ping_status"] => string(4)
        "open" ["post_password"] => string(0)
        "" ["post_name"] => string(16)
        "friday-recurring" ["to_ping"] => string(0)
        "" ["pinged"] => string(0)
        "" ["post_modified"] => string(19)
        "2023-12-13 13:16:49" ["post_modified_gmt"] => string(19)
        "2023-12-13 18:16:49" ["post_content_filtered"] => string(0)
        "" ["post_parent"] => int(0)["guid"] => string(69)
        "https://peabodyheights.wpenginepowered.com/?post_type=event&p=46" ["menu_order"] => int(0)["post_type"] => string(5)
        "event" ["post_mime_type"] => string(0)
        "" ["comment_count"] => string(1)
        "0" ["filter"] => string(3)
        "raw" ["dates"] => array(6) {
          ["2023-11-22"] => array(1) {
            [0] => array(2) {
              ["start_time"] => string(8)
              "10:00 am" ["end_time"] => string(7)
              "6:00 pm"
            }
          } ["2023-11-29"] => array(1) {
            [0] => array(2) {
              ["start_time"] => string(8)
              "10:00 am" ["end_time"] => string(7)
              "6:00 pm"
            }
          } ["2023-12-06"] => array(1) {
            [0] => array(2) {
              ["start_time"] => string(8)
              "10:00 am" ["end_time"] => string(7)
              "6:00 pm"
            }
          } ["2023-12-13"] => array(1) {
            [0] => array(2) {
              ["start_time"] => string(8)
              "10:00 am" ["end_time"] => string(7)
              "6:00 pm"
            }
          } ["2023-12-20"] => array(1) {
            [0] => array(2) {
              ["start_time"] => string(8)
              "10:00 am" ["end_time"] => string(7)
              "6:00 pm"
            }
          } ["2023-12-27"] => array(1) {
            [0] => array(2) {
              ["start_time"] => string(8)
              "10:00 am" ["end_time"] => string(7)
              "6:00 pm"
            }
          }
        }
      } ["start_time"] => string(8)
      "10:00 am" ["end_time"] => string(7)
      "6:00 pm" ["time"] => array(1) {
        [0] => string(16)
        "10:00 am-6:00 pm"
      }
    }
    }
    }
    } ["has_more"] => bool(false)
    }

    I have 2 recurring events for this case:

    1. Whiskey Wednesday – starts Nov. 22, Ends Dec. 27 and occurs every Wednesday
    2. Friday Recurring – Starts Dec. 8, Ends Dec. 28 and occurs every Friday

    I don’t see any of the Friday dates in the raw dates, just the Wednesday ones. Is this what the array should look like?

    Plugin Author Marc Bellêtre

    (@marcbelletre)

    Hi @neilsavage,

    In the output you can see that both events have the exact same dates (every wednesday from November 22 to December 27)

    In this case there are two options : either you misconfigured your Friday event, or there is something going on in the function that retrieves all the dates for a single event.

    Looking again at your code, it looks like you didn’t specified the post ID when retrieving the recurring dates field. When the ID is not specified the function takes the global post.

    In the fbdm_get_event_dates function you shall replace $recurrence = get_field('recurring_dates'); by $recurrence = get_field('recurring_dates', $post_id);

    Looking again at the post from where you pasted this code it was an error on my side. This code was an adaptation of a function that I use but I didn’t test it.

    Thread Starter neilsavage

    (@neilsavage)

    Hi Marc,

    That was it! Thank you for helping me with this, much appreciated. Great work with the plugin as well!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Trouble listing all events’ is closed to new replies.