kriegar Posted May 26, 2015 Share Posted May 26, 2015 (edited) Hi guys, Got a wee issue that hopefully someone here can clear up. I have a page with a field called features, the field type is page and it has pages that belong to it. I want to be able to query against that to return all the pages in a list that have one or more of those features ticked. Here is my code at the moment. What I would have thought is it would be something like featured.subfield = 1. $query = ''; if(isset($location) && $location != ''){ $query .= ",location=".$location; } if(isset($minPrice) && $minPrice != ''){ $query .= ",askingprice2>".$minPrice; } if(isset($bedrooms) && $bedrooms != ''){ $query .= ",number_of_bedrooms>=".$bedrooms; } if(isset($maxPrice) && $maxPrice != ''){ $query .= ",askingprice2<".$maxPrice; } $query .= ",start=".$start.",limit=".$limit; //var_dump($query); $saleproperties = $pages->get(1167)->children($query); $pagination = $saleproperties->renderPager(array('listMarkup' => "<ul class='pagination'>{out}</ul>")); echo $pagination; Edited May 26, 2015 by kriegar 1 Link to comment Share on other sites More sharing options...
DaveP Posted May 26, 2015 Share Posted May 26, 2015 Hi kriegar, and welcome! If I understand your question (and please forgive me if I don't), the subfield selectors are something you want to add to your selector string ($query above)? Incidentally, $query looks like it should work from what I can see, and you obviously (from var_dump($query); above), have a good handle on debugging your code. Have you seen http://processwire.com/api/selectors/#subfield ? It should be as easy as you expect (PW often is, and some times even easier than that). Also, take a look at https://processwire.com/api/fieldtypes/repeaters/ as that talks about the same sort of thing. Link to comment Share on other sites More sharing options...
kriegar Posted May 26, 2015 Author Share Posted May 26, 2015 Hi Dave, Thanks for the reply. I usually work with framework based php so I have a good grasp of the code and know how I would do this with raw sql however im still a bit fresh to some of the processwire stuff. Anyhoo yeah I tried that with the subfield stuff so I did $query .= ",features.garden=1"; however that just spits out an error saying unknown subfield. Here is a screenshot of the field as it looks from the admin panel. maybe I can specify the sub page id? or would I be able to specify that its the sub pages title that I am querying against if that makes sense. Link to comment Share on other sites More sharing options...
LostKobrakai Posted May 26, 2015 Share Posted May 26, 2015 You're using subfields the wrong way. "features" holds a few pages, which on their own hold fields. E.g. "features.title=Garden" would find all properties, which has (at least one) page selected in features, that has a title of "Garden". Subfields are in this case all the fields of the linked pages. You should be aware that theoretically titles could not be unique, therefore if you can't be sure about that you could fallback to using the id instead if the title. If you query multi-pagefields directly, then it automatically queries for id's so "features.id=1015" is the same as "features=1015". 1 Link to comment Share on other sites More sharing options...
kriegar Posted May 27, 2015 Author Share Posted May 27, 2015 Thats exactly what im trying to get haha. Ill try "features.title=Garden" and see how that works. it makes more sense than what I was doing and knew it would be something simple like that. Link to comment Share on other sites More sharing options...
kriegar Posted May 29, 2015 Author Share Posted May 29, 2015 Yeah that did the job. Thanks guys 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