Jump to content

Bacelo
 Share

Recommended Posts

Hi there,

I have a bit of trouble on filtering correctly some event pages by some selectors...

I do have the following 2 date fields:
- start date (fieldname = date)
- end date (fieldname = enddate)

Some events are a single day event (only start date) - some are a multi day event (end date).
Past single day events should not show up.
Current multi day events should show up (even if start day is in the past, but end date is future).

So I have the following selector:

if ($standort == '') {
	$termine = $page->children("sort=date, limit=10, (date>=today, enddate=''), (enddate>=today)");
} else {
	$termine = $page->children( "(standort_reference~=$standort), (standort_alle=1), (date>=today, enddate=''), (enddate>=today), sort=date, limit=10");
}

This selector

$termine = $page->children("sort=date, limit=10, (date>=today, enddate=''), (enddate>=today)");

works fine, but the follwing does not work (all past entries are also shown):

$termine = $page->children( "(standort_reference~=$standort), (standort_alle=1), (date>=today, enddate=''), (enddate>=today), sort=date, limit=10");

I have no clue what I'm missing - any ideas?

Link to comment
Share on other sites

You're using OR-groups, which means only one of the selectors in parentheses needs to match. This means if standort_reference or standort_alle match for a page, the other selectors don't matter. If you remove the parentheses around the selectors for standort_reference and standort_alle, the selector should work as intended. Alternatively, use named OR-groups if you want to use multiple groups of alternative selectors in your query:

https://processwire.com/docs/selectors/#or-groups

  • Like 2
Link to comment
Share on other sites

Thank you @MoritzLost for your reply ?.

I had a look at the OR-groups before, but I don't get it. As I understand by now - as you mentioned, if one OR fits, the other selectors then don't matter. So, my logic is wrong...

When I remove as mentioned the parenthesis for "standort_reference" and "standort_alle", I don't get any output anymore. ?

Actually I need to filter "$termine" twice:

-> standort_reference OR standort_alle
(standort_reference~=$standort), (standort_alle=1)

One of both above has to match - and additionally then

-> filter for both
(date>=today, enddate=''), (date!='', enddate>=today)

get all single day entries where "date" is only in the future AND additionally also all multi day events which are still present running ("date" in past and "enddate" in the future).

The part of "named groups" I do currently not understand how to get use of it in my part of code ?:

foo=(selector1), bar=(selector2), foo=(selector3), bar=(selector4)
Link to comment
Share on other sites

I think I got it... It works now by the following:

$termine = $page->children("standort=(standort_reference~=$standort), standort=(standort_alle=1), date=(date>=today, enddate=''), date=(date!='', enddate>=today), sort=date, limit=10");

At least It looks like the output is correct!?

  • Like 2
Link to comment
Share on other sites

4 minutes ago, flydev ?? said:

Try range() in your selector :


$selector = "range=(date>=1583017200, date<=1589493599)";

just replace the timestamps with your own.

Thank you.
Yeah, that's what I did now, as I do understand the "named groups" now correctly... my code looks finally now:

if ($standort == '') {
	$termine = $page->children("sort=date, limit=10, date=(date>=today, enddate=''), date=(enddate>=today)");
} else {
	$termine = $page->children("standort=(standort_reference~=$standort), standort=(standort_alle=1), date=(date>=today, enddate=''), date=(date!='', enddate>=today), sort=date, limit=10");
}

So I grouped by 2x date() and 2x by standort().

Is that correct coded now? Just to know, that I did understand it right.

  • Like 1
Link to comment
Share on other sites

18 hours ago, Bacelo said:

So I grouped by 2x date() and 2x by standort().

Is that correct coded now? Just to know, that I did understand it right.

Yes, that looks good! In both of the named groups, at least one of the selectors has to match for the entire group to match, like you wanted.

  • Thanks 1
Link to comment
Share on other sites

26 minutes ago, MoritzLost said:

Yes, that looks good! In both of the named groups, at least one of the selectors has to match for the entire group to match, like you wanted.

Thank you @MoritzLost ?

If I got it right, named groups are actually more then a OR selector, because (in my case) both selectoras will work. So it's more like a OR-AND selector.

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

×
×
  • Create New...