Sarnoc Posted May 12, 2019 Share Posted May 12, 2019 Hi All, Back again! Following on from my last post (useful for background), I'm now trying to build filters for my website to make it easier to find the correct page. I've used the Skyscrapers style of building an array but I can't work out how to insert logic into the filter. For example, I have the following set up within my filters: Year_Sunday (1 of the 3 Sunday years) Year_Weekday (1 of the 2 weekday years) Season (1 of 6 or so seasons, e.g. Lent) Week (1, number of weeks dependent on length of season) These are referencing page references, so each of those is a separate part of the site structure. In my code, I've just got: foreach(array('Liturgical_Year_Sunday', 'Liturgical_Year_Weekday', 'Liturgical_Season', 'Liturgical_Week') as $key) { if(!$value = $input->get($key)) continue; } as shown in the Skyscrapers demo. This gives me the ability to apply filters, but the logic appears to be OR rather than AND? For example, if I've got both Season and Week filters applied, (e.g. Lent, Week 4), I'll get any results that are tagged with Lent OR Week 4, when in fact what I want is the following filter logic: Liturgical_Year_Sunday OR Liturgical_Year_Weekday AND/OR Liturgical_Season AND Liturgical_Week I'm guessing it's something to do with how you build the selector, but I can't see that in the Skyscrapers code. If someone could give me some hints on where to find it and how to implement this, it would be much appreciated. Thanks Link to comment Share on other sites More sharing options...
dragan Posted May 12, 2019 Share Posted May 12, 2019 Not sure, but maybe sub-selectors or / and owner selectors may help: https://processwire.com/blog/posts/processwire-3.0.95-core-updates/ https://processwire.com/docs/selectors/#sub-selectors Link to comment Share on other sites More sharing options...
Sarnoc Posted May 13, 2019 Author Share Posted May 13, 2019 Ok thanks, I'll take a look. I'm really struggling with this so I'm just going to have to hack around with it until I can get something to work.. Link to comment Share on other sites More sharing options...
Robin S Posted May 13, 2019 Share Posted May 13, 2019 On 5/12/2019 at 10:07 PM, Sarnoc said: I'm guessing it's something to do with how you build the selector, but I can't see that in the Skyscrapers code. Yes, it is about how you build the selector. When you are dealing with input coming from a search form you usually build up the selector in a string variable $selector, adding pieces to $selector for each populated GET variable. But before you try that start with something simpler. Rather than building up a selector string dynamically, experiment with writing out different selector strings and supplying the selector to $pages->find() to see if you get back the pages you expect. The selectors documentation is here: https://processwire.com/docs/selectors/ Each "clause" you add to the selector works with AND logic by default: field_1=foo, field_2=bar This matches pages where field_1=foo AND field_2=bar. For OR logic with different fields and values, check the documentation for OR-groups. (field_1=foo), (field_2=bar) This matches pages where field_1=foo OR field_2=bar. Regarding OR conditions for multiple values in a single field, or multiple fields with a single value, see the following sections:https://processwire.com/docs/selectors/#or-selectors1https://processwire.com/docs/selectors/#or-selectors2 When you have sorted out what kind of selector you need to match the pages you want you can move on to building up the selector dynamically according to your GET variables. 2 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