Category-list uses the function wp_terms_checklist() in wp-admin/includes/template.php on row 90. The parameter “checked_ontop” is set to true. So the checked checkboxes will be on top.
This is only happening when editing a post, when I add a new one everything is fine and dandy
Thats because when you create a post, none of the categories are checked and the list will be intact, but when you saves one it will appear on the top because of the “checked_ontop is set to true”.
You can prevent this by changing the parameter checked_ontop to false by adding this to your theme function.php.
function wpse_prevent_on_top_cat() {
// Run only in admin
if( is_admin() && add_action('wp_terms_checklist_args', 'wpse_prevent_on_top_cat') ) {
// Change checked_ontop to false
$args['checked_ontop'] = false;
// Return the new parameter
return $args;
}
}
Or just install my simple plugin on this code: https://github.com/pontusab/WordPress-Category-List
The result: