olafgleba Posted February 2, 2023 Share Posted February 2, 2023 Hi, maybe i am too simple minded today, but my guess is that the following task is not possible(?): I have two datetime fields in a template, lets say Date_1 and Date_2. The template output ($pages->find()) is sorted by Date_1 in descending order. Now, if Date_2 is populated it should join the result output chronological. Example: I have 3 Pages Page => Date_1: 08.2.2023, Date_2: Ø Page => Date_1: 06.2.2023, Date_2: Ø Page => Date_1: 05.2.2023, Date_2: 07.2.2023 The default sorting gives me this: 1. Page 2. Page 3. Page Desired result: 1. Page 3. Page 2. Page Please, i would be delighted if you proof me wrong. ? Many thanks in advance Olaf Link to comment Share on other sites More sharing options...
Jan Romero Posted February 2, 2023 Share Posted February 2, 2023 The way ProcessWire selectors work, this should be sort=-Date_2|Date_1, although I’m neither sure where the hyphens go nor whether sorting allows the pipe operator at all. Alternativey, it’s easy in SQL with coalesce(), or you could add a hidden third field that precomputes to Date_2 ?? Date_1. Edit: doesn’t seem to be supported judging by this open PR https://github.com/processwire/processwire-requests/issues/107 1 Link to comment Share on other sites More sharing options...
olafgleba Posted February 2, 2023 Author Share Posted February 2, 2023 As both fields may be populated and wanting the behavior nonetheless, the "if one is empty, than..." doesn't fit anyway. But you gave a good hint with that hidden field approach. Thats the way to go, i think. Many thanks! Link to comment Share on other sites More sharing options...
monollonom Posted February 2, 2023 Share Posted February 2, 2023 I have the same case where I use a start date and an end one. I add a hook that checks the end date when saving the page and if undefined it copies the start date value, this way you can sort using the end date. 1 Link to comment Share on other sites More sharing options...
monollonom Posted March 20, 2023 Share Posted March 20, 2023 (edited) ? Edited March 22, 2023 by monollonom Link to comment Share on other sites More sharing options...
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