Manol Posted November 10, 2014 Posted November 10, 2014 Hello guys. I'm trying to find a list of products that can belong to several areas, the areas consist in a number or numbers separated by "|" like the following example: 1.- Some products: product = 31 -> areas = 3|16 belongs to area 3 and 16 product = 32 -> areas = 2|14 product = 33 -> areas = 5 product = 34 -> areas = 3 2.- Area I'm looking for: $area = 3 3.- My selector $products = $pages->get("/product/")->find("areas=$area"); 4.- results I'm getting product 34 whereas I would like to get product 31 as well. Any ideas? Thank you.
LostKobrakai Posted November 10, 2014 Posted November 10, 2014 If your areas field is a page field this should work whereas if it's a textfield with a string you need to use another operator like %= or *= .
Manol Posted November 10, 2014 Author Posted November 10, 2014 Yes its a textfile, the problem is that using *= in the following case $area = 3 product = 31 -> areas = 2|13 product = 34 -> areas = 3 It would match 3 and 13
muzzer Posted November 10, 2014 Posted November 10, 2014 I've used this type of method for various things in the past, perhaps not on PW, but the way I've done it is to surround the entire string with the "\" character, eg |2|13| This way I believe you can use the %=|3| selector to find only the 3 edit: and you could also use %=|3 to find 31, 310, 35 etc 1
LostKobrakai Posted November 11, 2014 Posted November 11, 2014 It there a reason to no use a pagefield? If not I would consider using it. It gives you really clean api calls and you get easy scalability on top.
Manol Posted November 11, 2014 Author Posted November 11, 2014 Can I use a regex in here? $products = $pages->get("/product/")->find("areas=$area");
Jan Romero Posted November 11, 2014 Posted November 11, 2014 No. If you really want to use this textfield approach, use muzzer’s technique and make sure every area is wrapped in pipe symbols, so you can select areas %= '|$area|'. However you should be aware that that’s not a good idea at all. If it’s at all possible to use pagefields, as LostKobrakai suggested, you should do that. Once you have set up your areas as pages, it will make everything much easier. 1
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