Jump to content
fruid

pipe selector not working

Recommended Posts

I think the pipe-selector should work as OR-operator but it doesn't. It only selects the option before the pipe, not after it. 

if($q) {
$selector = "template=article|blog_post|book, title|body|author*=$q, sort=$getsort, title^=$getletter, limit=25, has_parent!=2";
$matches = pages()->find($selector);
}

Any ideas?

Share this post


Link to post
Share on other sites

Your topic says 'pipe selector not working' There are two different uses of pipe selectors in your sample code. 

  1. template=article|blog_post|book - OR selectors: matching one value or another (docs)
  2. title|body|author*=$q - OR selectors, matching one field or another (docs)

Which one isn't working? Are you not getting any results or is it returning unwanted results? Are you sure it is not the AND selectors (docs) that are 'interfering'? Perhaps you want OR:groups (docs)?

  • Like 1

Share this post


Link to post
Share on other sites

I did some more investigation and updated the PW-version to ProcessWire 3.0.164 so that I can use the operator ~%=

Now it seems to work.

However, the issue persists with another page where I use ProFields-Table.   

$selector = "category=$category, name|text~%=$q, name^=$letter, sort=$getsort";

All the other selectors seem to work fine and search a specific column in the table but as soon as I use pipe it just wouldn't.

Share this post


Link to post
Share on other sites
47 minutes ago, fruid said:

Now it seems to work.

Great! Glad you got it sorted.

48 minutes ago, fruid said:

but as soon as I use pipe it just wouldn't.

Please explain what this means 😄 Zero? Wrong results?

50 minutes ago, fruid said:

where I use ProFields-Table.   

I'll try and replicate when I get a bit of time. Could you please clarify the field types in your selector? What is category and text?

Share this post


Link to post
Share on other sites
4 hours ago, kongondo said:

Please explain what this means 😄 Zero? Wrong results?

Exactly, I get no results, not for the left nor for the right part of the pipe. 

column "name" of type is "Tiny Text (up to 255 chars)"
column "text" is of type "Text"
and column "category" is of type "Select*"

The rest are no fields or columns, just additional filters passed to the server via HTML-form with get-method.

Thanks for looking into this

Share this post


Link to post
Share on other sites
1 hour ago, fruid said:

column "name" of type is "Tiny Text (up to 255 chars)"

Hmm. I've never tried this but I am curious ProcessWire didn't complain about a custom field called 'name'. I would've thought that is a reserved word since ProcessWire pages field has a name column.

1 hour ago, fruid said:

column "category" is of type "Select*"

Do you mean Select Options field (fieldtype)? 

Share this post


Link to post
Share on other sites

I now renamed the two fields name and text to something more specific but still no success.

See attached what I mean by "select*", it's an option field.

But there's no issue with that field, just with the two text fields mentioned and the pipe.

1911968259_Screenshot2020-08-05at22_36_45.png.5a3eccf342c4785f79d7f89df80872c2.png

Share this post


Link to post
Share on other sites
$selector = "category=$category, name|text~%=$q, name^=$letter, sort=$getsort";

I must say that I'm a bit confused about all this so might've completely misunderstood your point, but just to clarify: "name" and "text" were table column names, not fields on the page? And you're passing this selector to $pages->find() or pages()->find()?

If so, you would need to specify them as subfields: "table_field_name.name|table_field_name.text~%=$q, table_field_name.name^=$letter". The point is that now you're referring to the "name" and "text" fields of the page, not the "name" and "text" columns of a specific table field.

  • Like 1

Share this post


Link to post
Share on other sites

in my last post here I said fields, my bad, what I meant is column names inside a ProField table.

I use 

$matches = $page->books("limit=24, $selector");

books being the name of the ProFields Table on this very page.

The thing is, it works as long as I don't use a search term, so it looks to me as if passing the selector to the array works fine, except for where I use the pipe. The mentioned

category=$category

inside the selector is also referring to a column name inside the ProFields Table and I have no issue there. Either 

column_name~%=$q
column_text~%=$q

also return results but neither

column_name|column_text~%=$q
column_text|column_name~%=$q

do.

Thanks for help

Share this post


Link to post
Share on other sites
15 minutes ago, fruid said:

what I meant is column names inside a ProField table.

In that case, what @teppo said should do it (according to the docs in its support board):

$pages->find("books.category=something, books.text=$letter");

 

Share this post


Link to post
Share on other sites
$selector = "books.category=$category, limit=24";
$books = $pages->find($selector);

tried that now but it also doesn't work. I kept it simple here but I'm getting just one result:

echo count($books); // returns 1 

and the markup is empty. My guess is it's now counting the columns with that name, not the cells within it?

(and that's without even addressing the mentioned pipe-problem.)

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...