a-ok Posted August 18, 2017 Posted August 18, 2017 I'm wanting to retrieve a repeater (via it's page ID) and was currently using this (with $testID being the returned repeater item page ID) $result = $pages->get("id=$testID"); This works fine when I am logged in (as superuser) but when logged out it returns null (I guess because it's an admin page). I have tried doing this with no such luck... $result = $pages->get("id=$testID, include=all"); Any ideas? Thanks.
abdus Posted August 18, 2017 Posted August 18, 2017 Getting a page with its id should return that page regardless of its status or access settings. I am able to get a repeater page by its id using $pages->get(1039); https://processwire.com/api/ref/pages/get/ Using $pages->find(), however, takes page access and status into account
a-ok Posted August 18, 2017 Author Posted August 18, 2017 15 minutes ago, abdus said: Getting a page with its id should return that page regardless of its status or access settings. I am able to get a repeater page by its id using $pages->get(1039); https://processwire.com/api/ref/pages/get/ Using $pages->find(), however, takes page access and status into account I thought as much but this seems to only work when I'm logged in... <?php if ($this->input->post->action == 'randomTest') : // Get random test ?> <?php $pageID = $sanitizer->selectorValue($this->input->post->pageID); $testID = $sanitizer->selectorValue($this->input->post->testID); $result = $pages->get("id=$testID"); $text = $result->typefaces_detail_tests_text; // Random test text $size = $result->typefaces_detail_tests_size; // Related font size from random test text if ($result->next->id) { $next = $result->next(); // Next test element in the repeater } else { $next = $result->siblings->first; // If next doesn't exist (end of repeater rows) then back to start } return json_encode(['html' => $text, 'size' => $size, 'next' => $next->id]); ?> <?php endif; ?> $('.typeface__toolbar .reload a.trigger').on('click', function(e) { e.preventDefault(); var $this = $(this), pageID = $this.attr('data-page-id'), testID = $this.attr('data-test-id'); $.ajax({ url: rootURL + 'ajax/', type: 'POST', dataType: 'json', data: { 'action': 'randomTest', 'pageID': pageID, 'testID': testID }, success: function(data) { console.log(data); }, error: function (data) { console.log(data); } }).done(function(data) { console.log(testID); }); });
abdus Posted August 18, 2017 Posted August 18, 2017 Does $testID get posted correctly? There has to be a problem with the page id. Can you check the item id again (Admin > Repeaters > some-page-name > repeater-item)?
Zeka Posted August 18, 2017 Posted August 18, 2017 I had a situation when I needed to get next repeater item and I also was able to get it working only with "include=all". I'm not sure, but it looks like normal behavior as these pages are under "admin" branch.
a-ok Posted August 18, 2017 Author Posted August 18, 2017 4 minutes ago, abdus said: Does $testID gets posted correctly? There has to be a problem with the page id. Can you check the item id again (Admin > Repeaters > some-page-name > repeater-item)? Yep, it all works when I'm logged in... but when logged out it doesn't. Hmm...
a-ok Posted August 18, 2017 Author Posted August 18, 2017 Definitely works when logged in and returning values fine... must be a permissions thing.
a-ok Posted August 18, 2017 Author Posted August 18, 2017 I believe it may have something to do with the ->next() method... https://processwire.com/api/ref/page/next/ // Get the next sibling, even if it isn't viewable $sibling = $page->next("include=all");
a-ok Posted August 18, 2017 Author Posted August 18, 2017 This seems to now work... partially if ($result->next("include=all")) { $next = $result->next("include=all"); // Next test element in the repeater } else { $next = $result->siblings->first; // If next doesn't exist (end of repeater rows) then back to start } Only issue is that the if condition isn't returning false or NULL to then go back to start.. it seems to return '0'.
a-ok Posted August 19, 2017 Author Posted August 19, 2017 This is what I had to do... if ($result->next("include=all")->id != 0) { $next = $result->next("include=all")->id; // Next test element in the repeater } else { $next = $result->siblings("include=all")->first->id; // If next doesn't exist (end of repeater rows) then back to start }
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