froot Posted February 7, 2022 Posted February 7, 2022 what's wrong with my code, why doesn't this work?! $hidden = $pages->find("template=cast, status=hidden"); deleteHidden($hidden, $pages); function deleteHidden($hidden, $pages) { foreach ($hidden as $item) { $pages->delete($item); } }
AndZyk Posted February 7, 2022 Posted February 7, 2022 Hello @fruid, is your selector finding any pages? I think you have to add "include=hidden" to your selector: https://processwire.com/docs/selectors/#access_control Edit: Reading further, I think your selector should work. I have never used a selector with "status", so sorry I don't have a clue. ? Regards, Andreas 1 1
Jan Romero Posted February 7, 2022 Posted February 7, 2022 What happens when you run that code? The delete() method returns a boolean, try logging it to narrow down the problem. Btw, you don’t need to pass $pages to your function. This should work too: $hidden = $pages->find("template=cast, status=hidden"); deleteHidden($hidden); function deleteHidden($hidden) { foreach ($hidden as $item) { $item->delete(); } } Do these pages have children by any chance? In that case you should get an exception unless you move them away first, or specify that you want to delete them as well, using $item->delete(true). 1
froot Posted February 7, 2022 Author Posted February 7, 2022 I tried $item->delete(); but it didn't work. Never mind, I just use the Admin Actions module instead. Thanks anyway.
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