I have a big website with tons of content, and I would like to automatically add all pages and their children to the menu in the backend, so I can then rearrange them easily via drag and drop. I tried to use plugins such as Auto Submenu but it doesn't work, and when I am using it I cannot add any pages manually, as soon as I save they disappear from the menu again. Is there a code I could use in the database to add all pages with their children?
The helpers you'll need are wp_create_nav_menu() and wp_update_nav_menu_item().
This will allow you to create a menu and then, using a query posts loop, programmatically add every page in your site dynamically.
You can use the get_pages() helper to retrieve all pages from the DB.
<?php // These are default args and don't need to be set explicitly. // I've included them here for reference. $args = array( 'hierarchical' => 1, 'post_type' => 'page', 'post_status' => 'publish' ); $pages = get_pages($args); // loop goes here // foreach or while will work, whatever you are comfortable with ?>