Hook in when a post is deleted, check for the post type, then manipulate post_parent
of potential child posts (or delete the posts):
function wp_dev_174635_update_posts( $parent_id ) {
$parent = get_post( $parent_id );
if ( $parent->post_type !== 'type2' ) {
return;
}
$posts = get_posts( array(
'post_type' => 'type1',
'post_parent' => $parent_id,
) );
foreach ( $posts as $post ) {
// EITHER: Reset post parent entry
wp_update_post( array(
'ID' => $post->ID,
'post_parent' => 0,
) );
// OR: Delete post
// wp_delete_post( $post->ID );
}
}
add_action( 'delete_post', 'wp_dev_174635_update_posts' );
Related Posts:
- How to Add Custom Taxonomy To Woocommerce Plugin
- Prevent trash/delete action on specific post types
- How to add custom content template part for a custom post type on main query using a plugin
- register_taxonomy with multiple object type and update_count_callback
- How often do you need to register_post_type?
- How to use a dedicated template for the Custom Post Type from a plugin?
- Remove POST_TYPE from custom post type permalink
- How to register custom post types in a plugin?
- How to append element after thumbnail
- How to have the right design for a custom post type without accessing themes
- Custom Post Type | Fatal Error on register_post_type()
- Set object terms not working on plugin activation
- custom post type not showing in menu
- Custom posts don’t work
- Adding a custom post type taxonomy template in plugin
- Addition of custom option panel crashes Media Library & Admin Area
- How to Get WordPress custom post data in WooCommerce product meta panel? [closed]
- Custom fields for custom post type
- ACF in wordpress
- Unable to format dates to put in event calendar
- Custom post type in Custom widget – $listItem
- Validate Custom Post Type fields
- Types plugin custom post add_action hooks
- how can i show a google map in custom post type
- custom post type single page not found after aotumatic publish By the author’s robot
- Restrict Custom Post Type to One Item
- Custom Post Type Front Page Gives 404
- Show Post columns to specific users on condition
- Insert custom taxonomy into category query
- Run query on specific admin options page and send results to select field in another function
- Custom post type that lets users create a set of posts?
- Can’t save custom post type fields
- get_post_types doesn’t work in plugin
- Add Excerpt On Quicksand Plugin
- Custom Post Types in plugins?
- How to add post type in masonry posts elementory widget
- How do I alter the position of a Custom Post Type menu item within my plugin admin menu?
- Customize permalink when creating a post
- Custom Taxonomy Not Showing in Menu
- How to add the post ID (or any other post data) to a Contact Form 7 mail?
- Multiple post type queries (with specific arguments for each)
- Using custom page templates with plugin [duplicate]
- need advice on how to do a lists using custom post types – taxonomy vs postmeta
- GravityForm: Populate Dropdown with custom post type [closed]
- How to retrieve a custom post’s capability?
- Get all of user’s custom post types in WP Admin for plugin
- how to add extra meta box or textarea into custom post types
- Issue with pre_get_posts on custom post type archive pages
- Custom Post Type Navigation on Custom Field
- Use get_post_types to query only custom posts types
- Plugin translation not working apart from name and description
- Get rewrite slug of custom post type in template
- “add_post_type_support” with Custom Post Type & ACF
- Shortcode insertion in tab
- Custom Post Type rewrite
- Admin notice not displaying
- How to Get Current Custom Post Type Selected Taxonomy Term (Not All Terms)
- Can’t get order_by meta_value_num to work properly
- How to quickly reorder posts in the admin panel that will persist for the wp-api
- Custom Post Type: Upload Multiple Images
- WP_Query | ‘post_type’ doesn’t work
- Add CPT as subpage under custom page
- WooCommerce product search titles only
- check if post title in a custom post type exists in page
- Detect where custom post type is declared
- Metadata for a taxonomy – is there any WordPress way of doing this?
- How to hack YARPP plugin to find related posts for custom post type?
- Loco Translate: Custom Post and Custom Taxonomy Labels not translated in wp-admin menu
- Hook to override title, image and content
- Insert Multiple Post with Same Publish Button
- Why is conditionally loading a custom plugin’s code only on a specific custom post type causing the site content to disappear?
- Show listings from Impress Listing plugin in random order using taxonomy and terms
- Update menu when saving settings
- get_object_taxonomies() returns empty array for custom post type
- One-to-many post relationships that are displayed by category (using posts-to-posts plugin)
- WordPress theme custom capabilities not works
- How to retain $_POST data when submitting form to custom page
- No posts found – Custom Post Type show_ui
- Why get_posts() not returning only selected category posts from Custom Post Type?
- single-{cpt}.php ignored
- If post has custom field then display css-class
- How to customize a permalink (URL) structure?
- Plugin: register custom post types, child ready and performance best practices
- How to add a custom taxonomy to show up in a custom post type menu?
- Replace text in post from cvs
- Insert and then update post_type by wp_update_post
- Custom Post Types. Are there any disadvantages/advantages in using a plugin to develop them?
- add category name to permalinks on product page /category-name/product-name
- How can I make a custom post type sticky?
- Is it possible to create Custom Post plug-in?
- child of post type (custom)
- Give a permalink to Custom Post Types without title
- Getting template_include to work when allow_url_include is off?
- WordPress post_where & posts_join not working only for custom post type
- Add custom ID to CPT posts only create not update
- Add custom post type as submenu [closed]
- WordPress multiple custom post types capability conflict in a single menu
- Getting meta in editor plugin, and event triggering issue
- How do I set default meta value by post type?
- Orderby CPT custom fields not working