Delete Child Posts

Try it like this: $args = array( ‘post_parent’ => $parentid, ‘post_type’ => ‘custom-type’ ); $posts = get_posts( $args ); if (is_array($posts) && count($posts) > 0) { // Delete all the Children of the Parent Page foreach($posts as $post){ wp_delete_post($post->ID, true); } } // Delete the Parent Page wp_delete_post($parentid, true);

How to display list of child pages of parent page in wordpress?

Add this code to your functions.php. An explanation of the code is given below. function wpb_list_child_pages() { global $post; $id = ( is_page() && $post->post_parent ) ? $post->post_parent : $post->ID; $childpages = wp_list_pages( ‘sort_column=menu_order&title_li=&child_of=” . $id . “&echo=0’ ); //you can add `&depth=1` in the end, so it only shows one level if ( $childpages … Read more

Custom Post Type Permalink For Parent/Child, 404 Page Not Found Error

In answer to my own question: It turns out the WordPress permalink structure works perfectly well for custom types, e.g. example.com/recipes/lunch/sandwich/. This works exactly as expected if you set ‘hierarchical’ => true. What I was originally trying to do was unnecessarily difficult to execute, and requires properly setting up a custom permalink structure to avoid … Read more