adrian Posted April 2, 2013 Share Posted April 2, 2013 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 More sharing options...
Macrura Posted April 2, 2013 Share Posted April 2, 2013 maybe $images = $pages->find("parent=/visuals/, summary|title~={$input->q}, sort=title"); $images2 = $pages->find("parent=/visuals/, tags={$input->q}"); $images->import($images2); http://processwire.com/api/arrays/ 1 Link to comment Share on other sites More sharing options...
adrian Posted April 2, 2013 Author Share Posted April 2, 2013 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 More sharing options...
diogo Posted April 2, 2013 Share Posted April 2, 2013 Or like this: $images = $pages->get("/visuals/")->find("summary|title|tags.title~={$input->q}, sort=title"); Link to comment Share on other sites More sharing options...
Macrura Posted April 2, 2013 Share Posted April 2, 2013 right- if tags are a page select then diogo's way is better; if you do it with import, then you would need to probably sort the array at the end, instead of on the selector.. Link to comment Share on other sites More sharing options...
adrian Posted April 2, 2013 Author Share Posted April 2, 2013 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 More sharing options...
diogo Posted April 3, 2013 Share Posted April 3, 2013 Ya, in that case Macrura's solution is a good one. To sort at the end you could do like this: $images->import($images2)->sort("title"); 1 Link to comment Share on other sites More sharing options...
WillyC Posted April 3, 2013 Share Posted April 3, 2013 nevar.do this $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 3 Link to comment Share on other sites More sharing options...
adrian Posted April 3, 2013 Author Share Posted April 3, 2013 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 More sharing options...
WillyC Posted April 3, 2013 Share Posted April 3, 2013 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 1 Link to comment Share on other sites More sharing options...
SiNNuT Posted April 3, 2013 Share Posted April 3, 2013 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 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