Inconsistent results with user.subField subselectors when using *= operator

Recommended Posts

I have a template my-template that has a page reference field myUser. The field is set to a user with custom template (using $config->advanced). When I try to filter pages with my-template whose myUser.name or myUser.title includes a certain keyword, I get inconsistent results. Here's what I mean:

// works because tom is an exact match
$pages->find("template=my-template, myUser.name=tom");// doesnt work even though myUser name is 'tom'
$pages->find("template=my-template, myUser.name*=tom");// doesnt work despite myUser's title being 'Your Mom'
$pages->find("template=my-template, myUser.title*=tom");// doesnt work
$pages->find("template=my-template, myUser.title|myUser.name*=tom");// doesnt work at all
$pages->find("template=my-template, createdUser.name*=tom");// works
$pages->find("template=my-template, anotherPageField.title*=value");// works
$pages->find("template=my-template, anotherPageField.title|anotherPageField.body*=value");

Recently Browsing
0 members

Similar Content

Hi there! And thanks for Processwire!
This is rather a question than a feature request, maybe there's a well known solution which i missed.
So what about aggregation in selectors? Let's suppose we have a PW-powered shop where any product has a rating made by customers. Every time the user polls two data fields are updated: points and votes. The rating is calculated as this:
$rating = $page->points / $page->votes;
It was easy, yeah. But what about sorting products by their rating? Basically there are two ways of doing it:
Creating one more field called rating and updating it after every vote. For sure it will work, but we have to create an extra data field which in fact stores data based on two another fields. Bad practice i think.
Getting all products into array and applying a cutom sort function. Will work again, but this demands much more coding than using the native PW selectors.
But how could it be done in the best possible way? Let's imagine this:
$products = $page->children("sort=points/votes");
Or maybe this:
function rating($a,$b){
return $a->points/$a->votes > $b->points/$b->votes;
}
$products = $page->children("sort=rating()");
Okay, let's go even deeper. Maybe we need "virtual" fields which are not stored in DB tables like other PW fields but represent the dynamically calculated values?
$page->rating = function(){
return $page->points/$page->votes;
}
$products = $page->children("sort=rating");
Will be glad to see advice on the best practices. Thanks in advance!

Hi,
I'm having problems with seatching for a value in repeater.
One of pages have attached repeater called 'insight_repeater'.
This repeater has h1_tag (text field) and i'm trying to search for repeater items that contains 'lor' phrase.

And right now i'm trying to do simple search, looking for phrase 'lor'. I've tried many approaches, but nothins seems to work, so i want to ask what i'm doing wrong here:

Hi all,
I'm having an odd issue that I think is down to the selector I'm using but I can't track down the cause!
I'm using front-end AJAX search form on a list of product adverts (pages) where the product is made by a certain manufacturer (vendor). The manufacturer is chosen buy the person listing the adverts from a page field list of manufacturers who's parent is id=1034.
Most manufacturers are being found without an issue. The only one that's causing a problem is called 'Proj-ect" (the "-" being part of their brand name.
Here's my selector code:
$thisBrandProducts = $pages->find("template=advert,vendor.title~=$q,has_parent=1034,limit=20,created_users_id!=$susDealerList");
$susDealerList is a list of advertisers that are not currently live so pages should be excluded.
Could the "-" in the name be the issue with those pages not being returned? If so does anyone have any ideas of how I can get around this?
Thanks in advance!

Hello there! And thanks for Processwire!
It may appear a noob question but what about selectors like "field1=val1||field2=val2"? I mean that the page we're looking for should have field1=val1 OR field2=val2 . There's plenty of examples for cases like "field=val1|val2" but it's another case.
Practical example: frontpage uder registration. User should enter nick and email, and both of them should be unused by other registered users. It's logical to use something like
$userTest = $users->get("nick={$input->post->nick}|email={$input->post->email}");
But this doesn't work.
That's the best practice in this case? Thanks in advance!

Hello,
I passed through a lot of documentation about selectors and a few post in the forum but and I did not find my answer so I'll try here :).
Question: Is there a way to find pages that have a certain field attached to his template ?
Use case:
// Site structure
Products
Computers
Computer #1 (has field cached_details)
Computer #2 (has field cached_details)
Electronics
Test #1
Pet Supplies
Test #2 (has field cached_details but is empty)
// If I want to get all children of page "products" that contains the field "cached_details" I would do something like this
// $products => PageArray
$results = $products->children("has_field=cached_details");
// or this
$results = $products->children("cached_details!=null");
// Expected: $results would contains [Computer #1, Computer #2, Test #2]
// Instead I have to do this
$results = new PageArray();
foreach($products->children as $child) {
if ($child->hasField("cached_details") === true) {
$results->add($child);
}
}
Thank you in advance guys :),