a-ok Posted August 7, 2018 Share Posted August 7, 2018 Apologies if this has been asked before but couldn't find anything... I have a simple tag system set up, which uses an overview template. At the top of my template is as follows: if ($input->get("tags")) { // If GET ?tags= exists... $currentTags = $input->get("tags"); $currentTags = $sanitizer->text($currentTags); $products->filter("stock_detail_tags.name=$currentTags"); // Filter products by the tags $pageTitle = str_replace('|', ' > ', $currentTags); if (!count($products)) throw new Wire404Exception(); // If no returned data then return 404 } The issue is my URL for if someone selects a furniture tag is /stock/?tags=furniture|mirrors which will return pages that have either the furniture or mirrors tag. What I need to do is amend this so it'll only return pages that have both furniture and mirrors tags. I understand what I need to do (use the AND selector) but I'm a little unsure in this setup whether I should be changing the URL or the code? Link to comment Share on other sites More sharing options...
OLSA Posted August 7, 2018 Share Posted August 7, 2018 Hello, can you try this: if ($input->get("tags")) { // If GET ?tags= exists... $currentTags = $input->get("tags"); $currentTags = $sanitizer->text($currentTags); // tags=furniture|mirrors $selector = "stock_detail_tags.name=" . str_replace('|', ',stock_detail_tags.name=', $currentTags); $products->filter("$selector"); // Filter products by the tags $pageTitle = str_replace('|', ' > ', $currentTags); if (!count($products)) throw new Wire404Exception(); // If no returned data then return 404 } To get AND inside query, you need to repeat query parameter (target) inside selector (example: 'tags=foo, tags=bar'). Regards. 1 Link to comment Share on other sites More sharing options...
a-ok Posted August 7, 2018 Author Share Posted August 7, 2018 Yes this worked perfectly. I overlooked thinking to use str_replace. Much appreciated! 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