johnnydoe Posted June 6, 2019 Share Posted June 6, 2019 Dear ProcessWire-community, I have the following "page search" problem: In my processwire website I use some "pages" as "data-containers" (that are not actual pages on the frontend). Let's say I got a data-container that contains many subpages with the template-type "product" thath has the fields "headline", "image", "text" and "price". The products have no detail pages, but many products are added to category-pages by "page reference" in processwire. For each category I chose several "products" from the subpages of the products-data-container, and then I display them on the categories page. Now i want to search for all products that have the word "pencil" in their headline or description. For each result I want to link to all categories that contain this product. But what I get when I do $pages->find("text|headline%=pencil") are not the real pages, but the data-containers. But I want to get the pages that are referencing these products. Does anyone know, how to do this? Thanks in advance! Jonas Link to comment Share on other sites More sharing options...
wbmnfktr Posted June 6, 2019 Share Posted June 6, 2019 Something like this? <?php // Page sub-select - find pages based on previous selected pages // example: find all brand based on products // https://processwire.com/talk/topic/3553-handling-categories-on-a-product-catalogue/?do=findComment&comment=37833 // define array for brands $brands = new PageArray(); foreach($pages->find("template=productTemplate") as $product) { // add brand from product page to brands array $brands->add($product->brandField); }; 2 Link to comment Share on other sites More sharing options...
Robin S Posted June 6, 2019 Share Posted June 6, 2019 See the selectors documentation for sub-selectors: https://processwire.com/docs/selectors/#sub-selectors There are two syntaxes available: square brackets and dot, with the dot syntax being shorter and arguably easier to read, but having some limitations. It's not quite clear to me how many levels of nesting exist in your case but your selectors would look something like this with two levels of nesting: // Square brackets syntax $results = $pages->find("page_reference_1=[page_reference_2=[text|headline%=pencil]]"); // Dot syntax - probably not as useful in your case because pipe OR conditions are not allowed in the field portion of the selector $results = $pages->find("page_reference_1.page_reference_2.text%=pencil"); 1 Link to comment Share on other sites More sharing options...
johnnydoe Posted June 7, 2019 Author Share Posted June 7, 2019 Hey thank you so much for your answers. First at all I'm happy that it doesn't seem impossible what I'm trying to do. I will check out, if I can solve my problem with your advices and will write back here with more details when I have solved it. Have a nice weekend! 2 Link to comment Share on other sites More sharing options...
johnnydoe Posted June 14, 2019 Author Share Posted June 14, 2019 Ok, I got it to work now. The subselectors (https://processwire.com/docs/selectors/#sub-selectors) were exactly what I needed. I got some edge-cases where I need to do some special queries (based on some if statements), but the subselectors are quite powerful and helping me also with this. So, thank you very much! ? 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