Re4DeR Posted March 9, 2019 Share Posted March 9, 2019 Hello, I have structure of site like in picture. I use blog module to have basic post and categories structure. So I have field "categories" for posts. And this field is limited by template "category" . By default I get categories from site1 and site2. I cant use parent limitation coz I would like to have same field in site1 and site2. So I think I need to get root parent for current post and use categories with same parent. I think I am not able to use admin ui and I have to create custom php function? Or is it any other way? Or maybe I am completly wrong and there is some other, better way - I am using proccesswire first time but I am very satisfied with this cms. Thanks for any reply. Link to comment Share on other sites More sharing options...
kongondo Posted March 9, 2019 Share Posted March 9, 2019 (edited) Welcome to ProcessWire and the forums @Re4DeR. Something like below added in /site/ready.php should do the trick. If you don't have a ready.php file, just create one and namespace it to ProcessWire; $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'categories') { $sitePage = $event->arguments('page')->rootParent; $siteCategories = $sitePage->child('template=categories')->children; if($siteCategories->count()) { $event->return = $siteCategories; } } }); With the above code, individual posts in Site 1 will only be able to select categories from Site 1 and for Site 2, they'll only be able to select from their site. Please note: The page (reference) field is called categories The template of the 2 Categories pages (i.e. the parents of your individual categories) is called categories. In the page field categories, we don't input anything in the Selectable pages section. Give us a shout if you have any questions. Edited March 9, 2019 by kongondo 3 Link to comment Share on other sites More sharing options...
kongondo Posted March 9, 2019 Share Posted March 9, 2019 2 hours ago, Re4DeR said: So I think I need to get root parent for current post and use categories with same parent. Yes, you were on the right track, although there could be other ways of doing it as well depending on the site's setup. Link to comment Share on other sites More sharing options...
Robin S Posted March 10, 2019 Share Posted March 10, 2019 Another way this could be done is via the following "Selector string" for "Selectable pages" for the Categories field: template=category, has_parent=page.rootParent 2 Link to comment Share on other sites More sharing options...
Re4DeR Posted March 10, 2019 Author Share Posted March 10, 2019 Hi, thank you very much! I used Robin solution and it is working like a charm. 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