Skip Navigation

[Resolved] Delete all relationship link

This support ticket is created 3 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 2 replies, has 1 voice.

Last updated by patrizioT 3 years, 3 months ago.

Author
Posts
#2144441

Tell us what you are trying to do?
I have a custom post type A, that is related to custom post type B. B is also related to a custom post type C. When i cancel post A i want to unlink B from C too.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#2144509

i have done this coding, but is not disconnecting it. It's work the delete part, but not the disconnction of relationships.

/**
* Automatically delete child posts when deleting a parent
*/
add_action( 'before_delete_post', 'ts_delete_children', 9, 2 );
function ts_delete_children( $post_id, $post ){

$parent_type = 'intervento'; // Edit parent post type slug
$relationship_slug = 'intervento-piazza-di-lavoro'; // Edit relationship slug

if ( $post->post_type === $parent_type ){
$children = toolset_get_related_posts( $post_id, $relationship_slug, ['query_by_role' => 'parent','role_to_return' => 'child','args' => ['post_status' => [ 'publish', 'trash' ] ] ] );

if ( is_array( $children ) )
{
foreach ($children as $child)
{

$relationship_slug_militi= 'piazza-di-lavoro-milite';
$militi= toolset_get_related_posts( $child, $relationship_slug_militi, ['query_by_role' => 'parent','role_to_return' => 'child','args' => ['post_status' => [ 'publish', 'trash' ] ] ] );
foreach ($militi as $milite)
{
$relationship_slug_radio= 'radio-milite';
$radios= toolset_get_related_posts( $milite, $relationship_slug_radio, ['query_by_role' => 'child','role_to_return' => 'parent','args' => ['post_status' => [ 'publish', 'trash' ] ] ] );

foreach ($radios as $radio){
toolset_disconnect_posts('radio-milite', $radio, $milite );
}

}

wp_delete_post( $child );
}
}
}
}

#2144515

My issue is resolved now. Thank you!