Jump to content

Custom Sort Child Pages


Macrura
 Share

Recommended Posts

I have a property of a child page that runs through a custom function to get a sort of the pages (hex colors).

assuming i can get the page ids of all of the child pages in the right order, is there any way i can run a script to sort these child pages (in the admin), they need to stay manual sort after the script runs so that the users can then make adjustments to the sort...

Looked at some threads and the page sort function, but looks like it may require running a sql query to update that sort (?)

Link to comment
Share on other sites

Time ago I needed something similar. I solved it with a small script. You may use it as a starting point:

$media = wire('pages')->find('parent=1034,template=medium,include=all');
$media->sort('media_type,status,title');
foreach ($media->getValues() as $key => $medium) {
    $medium->of(false);
    $medium->sort = $key;
    $medium->save();
    // var_dump($key.' - '.$medium->sort.' - '.$medium->media_type.' - '.$medium->title);
}
  • Like 7
Link to comment
Share on other sites

cool - thanks, this works well! Now i just have to figure out how to update the sort on the pagetable for the parent page...

Edit: was simple, just need to sort the pagetable field on the runtime/temp property... awesome :)

  • Like 2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...