Hello, when I want to unpublish certain pages while looping through them, the sorting numbers seem to be confused and new pages are being created.
Lets imagine I have a list of pages, all with the template page
like:
1_page-one/page.txt
2_page-two/page.txt
3_page-three/page.txt
4_page-four/page.txt
and want to unpublish the second of them:
foreach( $pages as $page ){
if( $page->slug() === 'page-two' ){
$page->unpublish();
}
}
My pages now look like:
_drafts/page-two/page.txt # correct
1_page-one/page.txt # correct
2_page-three/page.txt # correct
3_page-three/default.txt # where does this come from?
3_page-four/page.txt # correct
4_page-four/default.txt # where does this come from?
Somehow two new pages were created with default
template. I assume that this is the classic reindexing problem when manipulating an array while looping through it. Do I need to skip one loop? Or reindex manually? Any idea how I could solve that?
Thank you very much!