Changing sitemap order programmatically

Permalink
I have a huge list of pages (recipes) that have a number as a page attribute.

I want to programmatically change the pages' sitemap order according to that page attribute.

Is there a way to do that? I'm on 5.6.

pekka
 
jero replied on at Permalink Best Answer Reply
jero
Maybe late to the party, but I've just used this successfully:

$pl = new PageList();
$pl->filterByPath('/products'); // substitute the appropriate path name
$pl->sortByName(); // sort the pages by name
$pages = $pl ->get();
if ($pages && is_array($pages)){
   foreach ($pages as $displayOrder => $page) {
      $page->updateDisplayOrder($displayOrder, $page->cID);
   }
}
pekka replied on at Permalink Reply
pekka
Looking good, thank you!