Jump to content

Selector "OR"


adrian
 Share

Recommended Posts

Hi everyone,

Hopefully a quick question.

I am trying to search through all pages by a keyword that is in any of the following fields:

title, summary, tags

The first two on their own are easy, as is the last on its own, but I am having a problem combining things to search through all fields because of the nature of the tags field I can't figure out quite how.

$images = $pages->get("/visuals/")->find("summary|title~={$input->q}, tags={$input->q}, sort=title");
 

That code forces the keyword to be in both summary|title and tags.

Thanks for any ideas!

Link to comment
Share on other sites

Thanks, that does the job just fine!

I would like to know if there is an option for doing it in one find statement though, just for simplicity's sake, although perhaps it really isn't that important in the end!

Link to comment
Share on other sites

Beautiful diogo - I should have delved into the structure of the tags field to figure that out.

Thanks!

Also Macrura73, thanks for making the point about sorting the array at the end!

On a more general level though I assume there is no way to use separate operators on different fields within a selector? I guess this is where you have to follow the approach of combining the results of two queries?

Link to comment
Share on other sites

nevar.do this  :angry:

$images = $pages->get("/visuals/")->find("summary|title~={$input->q}, tags={$input->q}, sort=title");

u.must   dothis

$q = $sanitizer->selectorValue($input->get->q);  

bfore selector u put.in

  • Like 3
Link to comment
Share on other sites

Good reminder, thanks! I am so used to sanitizing in pure PHP, but sometimes I forget with PW - I tend to assume it takes care of absolutely everything for you :)

And yes, also good to use "get" so it's not emulating "request"

Link to comment
Share on other sites

And yes, also good to use "get" so it's not emulating "request"

request.not

do get or do post

their.is no request

u.find only what u bring in

already know  that.witch u need

There's nothing like waking up to some of these yoda-like pearls of wisdom..thx Willy :)

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...