Jump to content

Search for text in page references


johnnydoe
 Share

Recommended Posts

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

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); 

};

 

  • Like 2
Link to comment
Share on other sites

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");

 

  • Like 1
Link to comment
Share on other sites

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!

  • Like 2
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...