Question

This is my first post here and I apologize if I explained too much or disrespected any rule.

There is a calendar plugin ("mk2 plugin" let's call it as it is not a public plugin) which is used to show events from programs (posts) in Wordpress. The only problem is it does NOT show the events when it comes to Sundays.

Every other day it works perfectly and shows the events for the whole week, even shows it for sundays. The calendar shows a week view and shows all the days events for the whole week but when we are on Sundays like today, it shows nothing of any thing.

I believe it has to do with the code at the end of this post because I changed the order in part of it:

                    $days = array(
            __("sunday", "mk2"),
            __("monday", "mk2"), 
            __("tuesday", "mk2"), 
            __("wednesday", "mk2"),
            __("thursday", "mk2"),
            __("friday", "mk2"),
            __("saturday", "mk2")
        );

and took Sunday to the end and Monday to be first. With that changed, it shows now only Sunday events and not other days which clearly was not the solution as it should show for events for all days (Wordpress start day setting is set to Monday). let me know if I should provide more information!

    $schedule_times = array();

    $post = get_post($program_id);

        $days = array(
            __("sunday", "mk2"),
            __("monday", "mk2"), 
            __("tuesday", "mk2"), 
            __("wednesday", "mk2"),
            __("thursday", "mk2"),
            __("friday", "mk2"),
            __("saturday", "mk2")
        );

        foreach($days as $index => $day) {
            $color = mk2_Toolkit::get_post_meta($post->ID, "accent_color", true, "#444444");


        $times = get_post_meta($post->ID, $day . "_time");

        $start_of_week = get_option("start_of_week");

        if($start_of_week == 0) {
            $last_day_of_week = 6;
        }
        else {
            $last_day_of_week = $start_of_week - 1;
        }

    $start = (date('w', strtotime("today")) == 0) ? strtotime("today") : strtotime('last sunday', strtotime("today"));

    if($start_of_week == 0) {
        $day = date("Y-m-d", strtotime("this $day", $start));
    }
    elseif($start_of_week == 1) {
        if($index == 0) {
            $day = date("Y-m-d", strtotime("next $day", $start));
        }
        else {
            $day = date("Y-m-d", strtotime("this $day", $start));
        }
    }
    elseif($index >= $start_of_week) {
        $day = date("Y-m-d", strtotime("-" . (7-$index) . " day", $start));
    }
    else {
        $day = date("Y-m-d", strtotime("this $day", $start));
    }
    if(!empty($times)) {

      foreach($times as $key => $time) {

        list($start_time, $end_time) = explode(",", $time);

        $start_date = "$day $start_time";
        $end_date   = "$day $end_time";

        if($end_date <= $start_date) {
            $end_date = date("Y-m-d H:i", strtotime("+24 hours", strtotime($end_date)));
        }


        array_push($schedule_times, array_merge($options, array(
            "id"      => mk2_Service::get_name() . "_" . $post->ID,
            "title"   => $post->post_title,
            "start"   => $start_date,
            "end"     => $end_date,
            "allDay"  => false,
            "color"   => $color,
            "url"     => get_permalink($post->ID)
        )));    
                }
            }
        }

        return $schedule_times;
  }

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top