SebastianP Posted yesterday at 12:47 PM Posted yesterday at 12:47 PM 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
Robin S Posted yesterday at 10:10 PM Posted yesterday at 10:10 PM 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"); 3 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now