Is there a way to batch update the page order attribute of all children of a specific parent, each time a new child is added?
More simply, is there a way to loop through pages and change the sort attribute so they are alphabetical?
For instance….
Would become…
And would ultimately be displayed in the admin as…
Hopefully this helps someone else
Dont forget to change “your_post_parent_id_here” with the parent id of your choosing.
global $wpdb;
$wpdb->query( 'SELECT @i:=-1' );
$result = $wpdb->query(
"
UPDATE wp_posts SET menu_order = ( @i:= @i+1 ) WHERE post_parent = 'your_post_parent_id_here' ORDER BY post_title;
"
);