OpenBayou Posted January 23, 2017 Share Posted January 23, 2017 I have a page called 'Podcasts ADs' with a field called 'podcast_show' that a repeater with a text field and an image uploader. Is there a way for the child pages in 'Podcasts ADs' to select data from those fields in the parent in the admin panel in the back-end? Example: If I enter in a show name called 'Show' in the text, I can select 'Show' in the child pages. Thanks. Link to comment Share on other sites More sharing options...
adrian Posted January 23, 2017 Share Posted January 23, 2017 $page->parent->podcast_show PS - have you checked out the cheatsheet? http://cheatsheet.processwire.com/ 1 Link to comment Share on other sites More sharing options...
OpenBayou Posted January 23, 2017 Author Share Posted January 23, 2017 Forgot to mention because I was sleep-deprived when I wrote the question, this is on the back-end on the Admin. Link to comment Share on other sites More sharing options...
Robin S Posted January 24, 2017 Share Posted January 24, 2017 Yep, you want a Page Reference field on the child pages. For "Label field" select the text field used in your repeater. Use the "Custom PHP option" for "Selectable pages" by creating the following hook in /site/ready.php: $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->name == 'my_page_reference_field') { $page = $event->arguments('page'); $event->return = $page->parent->podcast_show; } }); 3 Link to comment Share on other sites More sharing options...
OpenBayou Posted January 24, 2017 Author Share Posted January 24, 2017 I got it to show up on the back-end editor but it doesn't show the title. The field above is called 'podcast_shows_child' and this is on a child page. The above field is on the parent page that's a repeater called 'podcast show' and the two fields are an image and a text field. The image field is called 'podcast_show_image' and the text field is called 'podcast_show_name' Thanks for the help. I tried doing it myself but I've been working on this site for four days and I'm not thinking properly. P.S. This is the tree Link to comment Share on other sites More sharing options...
kongondo Posted January 24, 2017 Share Posted January 24, 2017 Show us the code in your /site/ready,php as per Robin's suggestion...Maybe you have a typo there. 1 Link to comment Share on other sites More sharing options...
OpenBayou Posted January 24, 2017 Author Share Posted January 24, 2017 1 hour ago, kongondo said: Show us the code in your /site/ready,php as per Robin's suggestion...Maybe you have a typo there. Have no idea what ready.php is. All I've done was change the field to page, did 'custom PHP code to find selectable pages'. <?php $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->name == 'podcast_shows_child') { $page = $event->arguments('page'); $event->return = $page->children->podcast_show; } });?> Link to comment Share on other sites More sharing options...
kongondo Posted January 24, 2017 Share Posted January 24, 2017 OK. It seems you are using an older version of ProcessWire, pre-dating the change in using custom code in page fields (can't remember in what version of ProcessWire 3.x this was introduced). Anyway, then the below is the FORMAT of the code that you need to enter in the custom code textarea. Adapt it to your needs; e.g. a suggestion was made for $page->parent->podcast_show but I see you are using children instead. Also note that I don't know what podcast_show is, so don't know if that code will return anything. This is just a pointer return $page->children->podcast_show; Link to comment Share on other sites More sharing options...
OpenBayou Posted January 24, 2017 Author Share Posted January 24, 2017 Solved it. Went the simpler route and created a hidden page and used the field to select those pages. Thanks for the help. One problem: the page is called 'podcast' and a field called 'podcast_shows' that lists pages from the 'podcast' page. How do I show the selected title from the field? '<?php echo $page->podcast_shows?>' shows the page ID. '<?php echo $page->podcast_shows->title?>' shows nothing. Link to comment Share on other sites More sharing options...
kongondo Posted January 24, 2017 Share Posted January 24, 2017 (edited) 1 hour ago, OpenBayou said: ...One problem: the page is called 'podcast' and a field called 'podcast_shows' that lists pages from the 'podcast' page. How do I show the selected title from the field? '<?php echo $page->podcast_shows?>' shows the page ID. '<?php echo $page->podcast_shows->title?>' shows nothing. Did you see this post in your other thread ? If podcast_shows is a multi-page field, it doesn't matter whether you have one or more pages selected in it; it will return a PageArray. Edited January 24, 2017 by kongondo 2 Link to comment Share on other sites More sharing options...
OpenBayou Posted January 24, 2017 Author Share Posted January 24, 2017 That was the problem. Had multiple pages instead of single. Thanks again. 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