Harmster Posted June 8, 2013 Share Posted June 8, 2013 Hey hey Now my title might seem confusing but this is essentially what i have: $items = $pages->find("template=match|notification, summoner_id=$summoner_string, sort=-create_date, limit=15"); And I want a field called notification_type to be equal to a certain amount of values, now what I first thought would work would be notification.notification_type = something but it doesn't The other template doesn't have the field notification_type so I cant just put it in there Any help? thanks Link to comment Share on other sites More sharing options...
nik Posted June 8, 2013 Share Posted June 8, 2013 I don't think that's possible with a single find as you'd need an or-selector like this (this is a pseudo selector, not an actual one): "template=match OR (template=notification AND notification_type=something), ...". One way is to use two find() calls and merge the resulting PageArrays but that isn't necessarily an option as you obviously need to sort and limit in the database (or at least you're doing it now). There is a trick you could probably use to get over the limitation in this case. This is clearly a hack so you have been warned =). create a field 'fake' of type integer and add it to the template 'match' make sure every page with template 'match' has the same value for field 'fake' ('-1' for example). Choose a value that never exists in field 'notification_type' (you'd need an autoload module just for filling the field 'fake'...) use a selector like this: "template=match|notification, notification_type|fake=something|-1, summoner_id=$summoner_string, sort=-create_date, limit=15" Now that's one hell of a dirty saturday night trick isn't it? But it works. I truly hope someone comes up with a better alternative. Or that you could live without those sort and limit selectors and use two finds instead of one. *** Edit *** Actually I just found a bit cleaner way, one without a fake field. Assuming field 'notification_type' can't have value of 'match' you can use this selector: "template=match|notification, template|notification_type=match|something, summoner_id=$summoner_string, sort=-create_date, limit=15" It's a trick as well, but not a dirty one anymore. Do note that there seems to be a limitation with builtin fields (or something else weird): you have to use 'template|notification_type', as using them the other way around results in an error "Field does not exists: template". I'll experiment on this a bit more and file an issue if it seems to be a bug. 1 Link to comment Share on other sites More sharing options...
Soma Posted June 8, 2013 Share Posted June 8, 2013 Now that you say I also stumbled on the same odd behavior of built in fields versus custom fields the order matters Link to comment Share on other sites More sharing options...
nik Posted June 8, 2013 Share Posted June 8, 2013 Soma, looks like it depends on the first field of the selector: if that one is native then other native fields work as well ("name|custom_x|template=..." works). But if the first field is custom, then only custom fields may follow ("custom_x|name|template=..." does not work). There's a todo comment in PageFinder.php regarding native fields not being multi-field aware (https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/PageFinder.php#L215), so it's technically not a bug but a known missing feature. It's even halfway done, just needs fields in certain order. 1 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