jan Posted September 3, 2012 Posted September 3, 2012 Hi there, I'm trying for hours the following: In the backend I have article pages containing a field "categories". The field "categories" has pages you can select via checkbox in the backend. These pages are status "hidden" under a node "system". It looks like this: Home Articles Article 1 (has selected e.g. /System/Category/print) Article 2 (has selected e.g. /System/Category/print and video) Article 3 System Category print internet video audio I've implemented a frontend search. There you can search all articles an you can select of which category the results are. My problem is, I don't have any glue, how I can filter the articles, to get only results for the categories selected. What can the selector string look like? Is there another way how I can do it? I ended up in very complicated "foreach"s and so on... Thanks a lot for your answers in advance!!
diogo Posted September 3, 2012 Posted September 3, 2012 On the selector the category must be a page. So be sure that you get the page of the chosen category like this $cat = $pages->get("parent=/category/, title=chosen"); Then you can do your search like this: $result = $pages->find("parent=/articles/, body*=$query, categories=$cat");
jan Posted September 3, 2012 Author Posted September 3, 2012 Hi, and thanks for your super fast reply! It works. I didn't know, that it is this simple! Realley great! But now I habe another problem: If I have a page that has the categories "print" and "video", I do it as you proposed, like this: $catPages = $pages->get("/system/category")->children->find("title=print|video"); as result I get returned the two pages from "system/category", which is correct. The results, when I perform my search like $result = $pages->find("parent=/articles/, body*=$query, categories=$catPages"); is a logical OR. So I get pages, having only the category "print" and other only having category "video", or both. My searchquery looks like this: articleCategory=1018|1020, limit=50, template=article Can you tell me, how I can do a logical AND in this case?! I want only pages that have "video" AND "print" selected. Thanks again!
interrobang Posted September 3, 2012 Posted September 3, 2012 The official docs say this: AND selectors: matching more than one value in the same field There will be instances where you need to say that a specific field matches more than one selector. This is simple, just specify all the conditions you need to match as separate selectors in the same string. For example: height>500, height<=1000 This AND selector matches all pages that have a "height" field greater than 500, and less than or equal to 1000. I didn't test, but something like this should work for you: $catPages = $pages->find('parent=/system/category, title=print|video'); $categories_selector = ''; foreach ($catPages as $catPage) $categories_selector .= ", categories={$catPage}"; $result = $pages->find("parent=/articles/, body*=$query $categories_selector");
jan Posted September 3, 2012 Author Posted September 3, 2012 Thats it. I tried it before, and it didn't work because of a mistake I made... Thanks a lot! That was exactly what I was looking for!! Works perfect!
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