CalleRosa40 Posted December 15, 2016 Share Posted December 15, 2016 Hi all! How can I unpublish/hide a repeater item using the API instead of manually toggling its status in the backend? I searched high and low in the forums but did not find much on the topic ... Knowing that repeater items are actually pages, I've tried playing around with $repeaterItem->addStatus(Page::statusUnpublished) and $repeaterItem->addStatus(Page::statusHidden). No luck though. What's the correct way to do this? Could someone please put me on the right track? Thanks! Link to comment Share on other sites More sharing options...
horst Posted December 15, 2016 Share Posted December 15, 2016 Are you sure that you dealing with the right pages / objects in $repeaterItem? Where do you call that, in template scope? How have you set outputformatting, true or false? Have you saved the page after changing the status? 1 Link to comment Share on other sites More sharing options...
adrian Posted December 15, 2016 Share Posted December 15, 2016 @CalleRosa40 - you may want to look at this: https://github.com/processwire/processwire-issues/issues/36#issuecomment-258702228 Firstly, it shows how to unpublish a repeater, but it also shows that there is currently a bug with this - at least as far as I can tell, but Ryan hasn't responded to my last post, so will have to wait and see. I'd love your feedback on that Issue if you can also confirm what I am seeing. 3 Link to comment Share on other sites More sharing options...
CalleRosa40 Posted December 15, 2016 Author Share Posted December 15, 2016 @adrian Thanks a lot. That was the right track indeed. Yes, I'm experiencing exactly the same strange behavior as described in your bug report. Setting $repeaterItem->status=2048 instead of using addStatus() works for me. For the record, from FieldtypeRepeater.module: Quote * Page status notes for repeater items: * - Unpublished & Hidden: Ready page, not yet used. Appears in unformatted repeater PageArray but user has not saved it. * - Unpublished & On: Publish requested and can be published as long as no input errors. * - Unpublished & NOT On: Item has been unpublished. * * Unpublished or hidden pages do not appear in formatted PageArray value, only in unformatted. @horst Thanks to you, too. Yep, I kept all that in mind. 2 Link to comment Share on other sites More sharing options...
adrian Posted December 15, 2016 Share Posted December 15, 2016 2 minutes ago, CalleRosa40 said: Yes, I'm experiencing exactly the same strange behavior as described in your bug report. Would you mind adding a note to that issue to confirm that you are seeing it also? Thanks! 3 minutes ago, CalleRosa40 said: Setting $repeaterItem->status=2048 instead of using addStatus() works for me. Yes, that works, but probably not a good idea, because status values are additive - it may not really matter with repeaters, but I would still recommend that we get Ryan to sort out the source of the problem. 1 Link to comment Share on other sites More sharing options...
CalleRosa40 Posted December 16, 2016 Author Share Posted December 16, 2016 @adrian I just added my two newbie cents to the Github thread. A slightly cleaner and more "additive" solution would be this, I guess: $repeaterItem->addStatus(Page::statusUnpublished); $repeaterItem->removeStatus(Page::statusOn); However, that's still a rather ugly workaround for PW's confusing behavior. 1 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