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);
Related Posts:
- Check if post has children or not
- WordPress Child Category Display All Posts
- Showing categories and subcategories with posts
- Get current post’s child page?
- I have a website issue I am trying to resolve
- How to Create Editable Blocks of Text for the Homepage?
- Set Post Title to Read-only and Disable Permalink Slug Editor in Gutenberg
- how to get permalink using sql
- Get the user type of an author
- Related posts display randomly by tag
- How can I edit a post from the frontend?
- Edit meta data does’t work with custom sql
- How to add an admin function only to posts, not pages?
- Check if Currently on Static Posts Page
- get next next post in single.php
- Unable to modify(update) posts – Page not found
- Featured Posts for Category Pages
- Fatal error post.php help :(
- Cannot Update A Post, 404 Error
- When paginating a Page with the tag, how can the 2nd and subsequent page styles be customised?
- Hiding posts in a list from specified categories
- Disable Post/Page comment emails for creators
- Changing html lang depending on author
- How many post WordPress can handle?
- Create an article from another Java application
- WP_Query do not load specifed number of post
- Manually removing revision post types
- Display most recent post in full, excerpts of older posts
- Buddypress activity id
- Modify WP_Post before processing
- How to rename “Publish” metabox title in post screen
- Tags to Post-ID mysql query. Tag Search
- Specifying # of Posts per page using inline post plugin (:
- Display post from current category and same tag?
- How to display WordPress archive into three columns [closed]
- Applying $posts_clauses filter to specific queries only
- Paginated Posts – Social Media Buttons Share First Page URL
- edit_form_after_editor only in post edit pages
- Using custom post template
- Display post option on frontend
- Create new posts in bulk using existing post
- Problem with adding programmatically woocommerce product post into category
- Post id algorithm in WordPress
- Show the content that is after the excerpt using child theme
- How to put link in twenty fourteen theme? [closed]
- Change target of view link in admin
- Switch to page template when using post permalink
- how to add older post to new wordpress post with new post?
- How not display particular post?
- Pasting code into WordPress post – LFs being eaten
- Insert sometext after first h3 in content
- Shortcodes on my website stops working after theme update [closed]
- Remove password protected posts from default RSS feed
- Show posts by author of membership level (Paid Membership Pro)
- How can you display all sibling categories to a post?
- How to disable the_excerpt from one post
- Blog post not showing title
- Category page when using static front page
- retrieve the oldest post id
- How do you search for a post or page with a certain url on the WordPress admin panel?
- How to check in functions.php if there is data in a WP_Query?
- why str_replace targeting pages instead just targeting post?
- Simple Custom Metabox Not Saving
- Access last visit time to a post
- why the posts queried from sql is more than those showed on the page?
- Get current taxonomy and display query accordingly
- Is there a function to get post info for any publish_status by post ID?
- Add static text to post URLs
- Display a specific category in a focused area of my site
- Target only single product page
- Check if almost 10 year old – working code is up to date
- Post Image Gallery After Content Function messes with other content
- Posting an article containing mathematical symbols and R code
- Query custom post type custom meta key
- WordPress: Develop multiple posts with different data
- Bulk find & replace on WordPress posts/pages (minus image paths)
- How can get the last post date of the user?
- How to convert attachment pages to Posts?
- Remove pagination if search returns empty
- Remove HTML tags from all posts
- Page with Category Returning 1
- Ajax post doesnt call succes after got the response
- Adding a ‘section’ to the backend menu
- Customizing URL slugs of Custom Post Type and Taxonomy make posts/pages 404
- Get 5 most recent categories
- Allow reader to reorder posts for themselves (oldest first)
- Is it possible to completely replace a post with an action/filter?
- Surrogate ID for posts, is there an alternative field in the posts table?
- Post preview in iframe without saving the post
- Set post beginning date and final date
- How do I get thumbnails?
- Using Post ID and Page ID in same function
- How can I show my post under a certain content name?
- How to display only one post on first category page and rest on next pages?
- Show Custom Post From Logged In Author
- Viewing category won’t show up Custom post type posts
- Get attachment if matches a variable
- Trying to create shortcode listing custom posts, but formating not being included
- How to make the Post Author name fixed as “Editorial Staff” even if there are multiple authors?
- Trying to create parent for post. I need some help. Thanks