Jump to content

How to use selectors include=hidden only with specific template?


Hurme
 Share

Recommended Posts

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

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

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

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

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

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");

 

  • Like 3
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...