Jump to content

Show one past event and all future events. Put in trash after datetime is over?


Roych
 Share

Recommended Posts

Hello,

I need some help with simple restaurant food menu, I'd like to show yesterdays menu and 6 future days (all together 7 days). My problem is that I'm not sure how to show -1 day with all future days. 

Another problem I have is that I don't need time in my datetime field ("Start_date") the menu should stay there entire day till midnight. But the day starts with 0:00:00 hrs and if I want the past event to go to trash, it goes in the morning not at midnight. (it puts todays event in the trash) Kind a lost here. 

it should show days like

Wednesday (yesterday) | Thursday (today) | Friday | Saturday | Sunday | etc ...

I show my "events" with

<?php $events = $pages->find("template=calendar-post, Start_date>=today-1, sort=end, limit=7"); ?>
<?php if(count($events)): ?>

// my event code

For dates I also tried with:

<?php $today = date('d. m. Y');
$start = date('d. m. Y', $single->getUnformatted('Start_date') . " 00:00:00"); ?>

And for trash I use:

<?php
  $ptrashed = $pages->find("template=calendar-post");
    foreach($ptrashed as $ptrash) {
    if(time() > $ptrash->getUnformatted("Start_date")) {
    $pages->trash($ptrash);
} } ?>

I'm not good with php so any help appreciated.

Thank you very much for helping.

R

Link to comment
Share on other sites

This should do the trick to get all events from yesterday and the next 6 days.

// define yesterday
$yesterday = strtotime("-1 day");
// make $yesterday match the saved date format
// in this case: dd.mm.yyyy
$yesterdayForSelector = date('d.m.Y', $yesterday);
// get our pages
$events = $pages->find("template=template, limit=7, date>=$yesterdayForSelector");

 

  • Like 3
Link to comment
Share on other sites

2 hours ago, wbmnfktr said:
// define yesterday
$yesterday = strtotime("-1 day");
// make $yesterday match the saved date format
// in this case: dd.mm.yyyy
$yesterdayForSelector = date('d.m.Y', $yesterday);
// get our pages
$events = $pages->find("template=template, limit=7, date>=$yesterdayForSelector");

Nice, it works great. Now only the datetime and putting in the trash. Defining the $yesterday simple. 

Thank you very much ;)

  • Like 1
Link to comment
Share on other sites

Not sure for trashing the events but would something like this work?

I need to leave yesterday published but all older ones put in a trash.

<?php 
$preyesterday = strtotime("-2 days");

  $ptrashed = $pages->find("template=calendar-post, Start_date>=$preyesterday");
    foreach($ptrashed as $ptrash) {
    if(time($preyesterday) > $ptrash->getUnformatted("Start_date")) {
    $pages->trash($ptrash);
    }
    } 
?>

or

<?php

        $eventpages = wire("pages")->find("template=calendar-post, include=all");
        foreach ($eventpages as $eventpage) {
            $enddate     = $eventpage->Start_date;
            $currenttime = time("-2 days");
            if ($enddate < $currenttime) {
                $pages->trash($eventpage);
            }
        }

?>

Thank you

R

Link to comment
Share on other sites

Either I'm missing an important detail or ...

// define yesterday
$theDayBeforeYesterday = strtotime("-2 day");
// get our pages
$reallyOldEvents = $pages->find("template=template, date<=$theDayBeforeYesterday");

foreach($reallyOldEvents as $oldEvent){

    // let's do something with it
    // maybe we put them into an archive
    // and delete all of them in 2 years
    // rather than now.

}

Does this find your events prior to yesterday?

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...