Tom. Posted January 19, 2016 Share Posted January 19, 2016 Hello, Just trying to figure this one out. I have a PageField which pulls Categories. Each Category will have Sub-Categories as it's children. So I have two PageFields on the page, Category and Sub Category. I want the Sub-Category PageField to pull back results based on the Category. I thought maybe like Visibility and Required If, I'll be able to use values from fields on that page. So under "Custom selector to find selectable pages" I tried "parent=category" <- Category being the PageField. Does anyone know how to do this, or if this is even possible? EDIT: Figured it out, I used the PHP code instead Link to comment Share on other sites More sharing options...
adrian Posted January 19, 2016 Share Posted January 19, 2016 Try: return $pages->find("template=subcategory"); 1 Link to comment Share on other sites More sharing options...
Tom. Posted January 19, 2016 Author Share Posted January 19, 2016 Thanks, I completely forgot to put in the return, now to get it to return rules based on the other PageField. I tried: return $pages->find("template=subcategory, id=$page->category"); Didn't quite work. I thought I worked it out. Link to comment Share on other sites More sharing options...
adrian Posted January 19, 2016 Share Posted January 19, 2016 Thanks, I completely forgot to put in the return, now to get it to return rules based on the other PageField. I tried: return $pages->find("template=subcategory, id=$page->category"); Didn't quite work. I thought I worked it out. Is the category page field's "Dereference in API as" setting set to Multiple or Single? 1 Link to comment Share on other sites More sharing options...
Tom. Posted January 19, 2016 Author Share Posted January 19, 2016 Is the category page field's "Dereference in API as" setting set to Multiple or Single? Sorry, you're right. It's a Single, however I've tried: return $pages->find("template=subcategory, id={$page->category->id}"); Still nothing though strangely. EDIT: Haha, never mind I'm being silly. I had a complete brain freeze there. Battling with a cold. Thank you for your help Adrian. I needed: return $pages->get($page->category)->children(); One question though, is it possible to reload the field via AJAX when the category changes? Link to comment Share on other sites More sharing options...
adrian Posted January 19, 2016 Share Posted January 19, 2016 Haha, never mind I'm being silly. I had a complete brain freeze there. I was wondering about that actually - how the id of the page could match the category id One question though, is it possible to reload the field via AJAX when the category changes? Good question - it is possible, but you need to do things a little differently. Try the following in the custom selector option - not the custom PHP option: parent=page.category 3 Link to comment Share on other sites More sharing options...
Tom. Posted January 19, 2016 Author Share Posted January 19, 2016 I was wondering about that actually - how the id of the page could match the category id Good question - it is possible, but you need to do things a little differently. Try the following in the custom selector option - not the custom PHP option: parent=page.category Perfect, thank you very much 2 Link to comment Share on other sites More sharing options...
Tom. Posted January 25, 2016 Author Share Posted January 25, 2016 Quick question on this - How do I make this visible only if it has results? It's set as a single page. I've tried a few things such as subcategory!='', subcategory!=0, subcategory.count>0 etc. I guess this isn't possible as the checks are based on the value of the field. Not the amount of pages returned. Based on that I tried category.children.count>0 however that always displayed the field. However I don't think this is possible either as I believe this only works on count at the moment? 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