Hurme Posted January 23, 2019 Share Posted January 23, 2019 So I spend couple of hours trying to find a solution for a problem that must be pretty common, but didn't find any simple solution. I'm building a search for a website and I need to find pages from certain templates, and in one of these templates that selector must include hidden pages. Something like "template=x|y|z OR (template=a, include=hidden), (title|body~=$searchquery)". Is there any way to combine all this in one selector? Link to comment Share on other sites More sharing options...
kongondo Posted January 23, 2019 Share Posted January 23, 2019 OR-groups is your answer. Have a look here: https://processwire.com/docs/selectors/#or-groups Link to comment Share on other sites More sharing options...
Hurme Posted January 23, 2019 Author Share Posted January 23, 2019 Hi kongondo, That was one of the first things I tried, but I couldn't get it to work. Any chance of writing down a simple example? $selector = $pages->find=("(template=x|y|z), (template=a, include=hidden), (title|body~=$searchquery), (bunch|of|other|fields~=$searchquery), (even|more|fields~=$searchquery)") The above obviously doesn't work, and I'm having problems following the logic. Link to comment Share on other sites More sharing options...
KarlvonKarton Posted January 24, 2019 Share Posted January 24, 2019 On 1/23/2019 at 2:50 PM, Hurme said: writing down a simple example I had to create a similar selector today, so I share as an example: $paramdate = strtotime('2018-01-01'); $numPanden = $pages->find("template=panddetail,(ska_Status=FOR_SALE),(ska_Status=SOLD,ska_PropertyModified>$paramdate),ska_Project=0"); Why are you having round brackets around every field? My guess is that you only need brackets around the template field? Link to comment Share on other sites More sharing options...
kongondo Posted January 24, 2019 Share Posted January 24, 2019 On 1/23/2019 at 1:50 PM, Hurme said: Hi kongondo, That was one of the first things I tried, but I couldn't get it to work. Any chance of writing down a simple example? I can confirm it doesn't work if an 'include' statement (unpublished, hidden or all) is added. I'm not sure if this is by design or it is a bug. Link to comment Share on other sites More sharing options...
ottogal Posted January 24, 2019 Share Posted January 24, 2019 On 1/23/2019 at 2:50 PM, Hurme said: $selector = $pages->find=("(template=x|y|z), (template=a, include=hidden), ... You could try this: $selector = $pages->find=("(template=x|y|z|a), (template=a, status=hidden), ... See https://processwire.com/docs/selectors/#access_control : Quote The examples above are all focused on including pages in results that wouldn't usually be included, among other pages. But lets say that you want to find only pages that have a hidden, unpublished or locked status. This is a fairly uncommon need, so no need to commit this to memory, but we'll include it for completeness. You can do it by querying the "status" property: status=hidden indicates that you only want pages with hidden status to be included in the results. status=unpublished indicates that you only want pages with unpublished status to be included in the results. status=locked indicates that you only want pages with locked status to be included in the results. Link to comment Share on other sites More sharing options...
Robin S Posted January 24, 2019 Share Posted January 24, 2019 On 1/24/2019 at 1:40 AM, Hurme said: Something like "template=x|y|z OR (template=a, include=hidden), (title|body~=$searchquery)". I had to do something like this recently. The "include" clause in the selector applies to the whole selector - you cannot have an include clause apply only to one OR-group. So the solution is to use include=hidden outside of the OR-groups, then exclude hidden pages within the OR-groups where you don't want the include=hidden to apply. So the selector for your example above would be: $results = $pages->find("(template=x|y|z, status!=hidden), (template=a), title|body~=$searchquery, include=hidden"); 3 Link to comment Share on other sites More sharing options...
Hurme Posted January 25, 2019 Author Share Posted January 25, 2019 I see, so in a way you have to go about it in reverse. I moved the whole hidden problem inside a foreach loop that spits out the search results, but it's good to know this is solvable by the selector alone. Thanks! 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