Jump to content

Recommended Posts

Posted

Hi community,

I need help with a selector. For example I want to find all events on a monday. "event_date" is a datetime-field. 

"template=event, event_date.???=1"

"???" should represent the weekdays number of the date - is there a way to get this run? 

Thank you for any help, best regards
Sebastian

Posted

You would need to use an SQL query to first get the IDs of matching pages, then use those IDs in a PW selector.

MySQL has a DAYOFWEEK() function but it starts the numbering on Sunday which is easy to forget. So probably better to use the DAYNAME() function instead.

// Get the IDs of all pages where the day name of the date value is Monday
$fieldName = 'event_date'; // The name of your date field
$tableName = "field_$fieldName"; // The table name is the field name prefixed with "field_"
$weekday = 'Monday'; // The day of the week you want to match
$stmt = $database->prepare("SELECT pages_id from $tableName WHERE DAYNAME(data) = :weekday");
$stmt->bindValue(':weekday', $weekday);
$stmt->execute();
$ids = $stmt->fetchAll(\PDO::FETCH_COLUMN);
$idsStr = implode('|', $ids);

// Find PW pages
$items = $pages->find("template=event, id=$idsStr");

 

  • Like 3
  • Thanks 1

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
  • Recently Browsing   0 members

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