Jump to content

Search children but don't retrieve them (or exclude them)


elabx
 Share

Recommended Posts

Hi! I am working on a real estate site and I will create variations of each listing as child of each listing (with the exact same fields) and combine the information in the frontend. Question is, how I could leverage searching fields in the listing AND variations but, I wouldn't want to get Pages that are listing variations. How could I account for: Found "4 bathroom" option inside variation, but I only want to retrieve the parent which is the main listing posting page. What occurs to me is:

$result = $pages->find(field1=data, field2=data, template=listing|listing_variation);

$only_variations = $result->filter("template=listing_variation");

//import only parents, if already present, will not import
foreach($only_variations as $variation){
	$result->import($variation->parent);
}
//Remove the pages variations
$final_results = $result->not("template=listing");

 

Think it will work? Would there be a more efficient way? 

Link to comment
Share on other sites

I think you should be able do this...

$result = $pages->find("template=listing, (field1=data, field2=data), (children.field1=data, children.field2=data)");

...but it's giving me buggy results when using child fields in the selector (works as expected for name and ID). Will do some more testing later and look at filing a GitHub issue.

Alternatively consider including the variation pages in a field within the listing page (i.e. Repeater, PageTable or Page Reference field) so you can match their containing page in the selector.

Link to comment
Share on other sites

6 hours ago, Robin S said:

I think you should be able do this...


$result = $pages->find("template=listing, (field1=data, field2=data), (children.field1=data, children.field2=data)");

...but it's giving me buggy results when using child fields in the selector (works as expected for name and ID). Will do some more testing later and look at filing a GitHub issue.

Alternatively consider including the variation pages in a field within the listing page (i.e. Repeater, PageTable or Page Reference field) so you can match their containing page in the selector.

WOAHH children.field that's some awesome selector right there. ^-^
 

6 hours ago, Robin S said:

Alternatively consider including the variation pages in a field within the listing page (i.e. Repeater, PageTable or Page Reference field) so you can match their containing page in the selector.

$result = $pages->find("template=listing, (field1=data, field2=data), (pagefield.field1=data, pagefield.field2=data)");

 

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