Skip Navigation

[Resolved] Go to parent post after delete child post

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 7 replies, has 2 voices.

Last updated by Miguel 1 year, 11 months ago.

Assisted by: Minesh.

Author
Posts
#2569449

Tell us what you are trying to do?
I have a template that shows a Course (cpt).
It has a view that shows Subscirbers (cpt) that are subscribed to that Course
That view shows the title with a link to that subscriber.
In the subscribre template I added a DELETE button following this article: https://toolset.com/course-lesson/deleting-content-from-the-front-end/

Can I make it go back to the course it came from after deleting?

Is there any documentation that you are following?
https://toolset.com/course-lesson/deleting-content-from-the-front-end/

Is there a similar example that we can see?

What is the link to your site?
hidden link

#2569881

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I would like to know what is happening currently when you delete the post?

Do you mean you are listing all child post using a view on a different page and there you are trying to delete the child post? Maybe few screenshot or video will help me what is happening currently and how you configured your current structure and how its working currently.

#2570127

I recorded an explanation of what I'm trying to do:

hidden link

#2570179

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thank you for sharing the video.

What if you try to use the hook "cred_redirect_after_delete_action" and adjust the code as per your requirement:
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_redirect_after_delete_action

If that does not help I will require problem URL where I can delete the post and admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2571889

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

With most of the course or subscribers page I can see there is 404 error:

No encontrado, error 404

Can you please tell me where you added the delete button on post I can find that, can you please share problem URL of the post where I can see the delete button.

#2571955

Oops, excuse me! I had forgotten to update the permalinks.
Try now.

#2572481

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added the Toolset form's hook "cred_redirect_after_delete_action" to your current theme's functions.php file:

add_filter( "cred_redirect_after_delete_action", "func_redirect_after_delete", 10, 2 );
function func_redirect_after_delete( $url, $post_id ) { 
global $wpdb;
 
   $current_post = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."posts Where ID=".$post_id);
   
	   $relationship_id = 0;
       if($current_post->post_type=='inscripto'){
        /// from table "wp_toolset_relationships" relationship slug =	fecha-inscripto
			  $relationship_id = 4; 
        
		}else if($current_post->post_type=='fecha'){
			/// from table "wp_toolset_relationships" relationship slug =	curso-fecha
			  $relationship_id = 1; 
		}
		
		 $res = $wpdb->get_row("SELECT DISTINCT ".$wpdb->prefix."toolset_connected_elements_2.element_id AS selected_parent_id
								FROM ".$wpdb->prefix."toolset_associations AS associations JOIN ".$wpdb->prefix."toolset_relationships AS relationships
								ON ( associations.relationship_id = relationships.id ) JOIN ".$wpdb->prefix."toolset_connected_elements AS wp_toolset_connected_elements_1
								ON ( associations.child_id = wp_toolset_connected_elements_1.group_id ) JOIN ".$wpdb->prefix."toolset_connected_elements AS wp_toolset_connected_elements_2
								ON ( associations.parent_id = wp_toolset_connected_elements_2.group_id )
								WHERE ( associations.relationship_id =".$relationship_id." )
								AND ( ( wp_toolset_connected_elements_1.element_id IN ( ".$post_id." ) ) )
								AND ( ( ( 1 = 1 )
								AND ( 1 = 1 )
								AND ( 1 = 1 ) ) )
								AND ( relationships.is_active = 1 )
								LIMIT 1 OFFSET 0",ARRAY_A);
				
				
				
					if(!empty($res)) {
						$parent = $res['selected_parent_id'];
						return get_permalink( $parent );
						exit;
						
					}
    return $url;
}

Can you please confirm now it works as expected.

#2572947

My issue is resolved now. Thank you!