Skip Navigation

[Resolved] Delete post in relationship

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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 9 replies, has 3 voices.

Last updated by Luo Yang 3 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#2133541

Tell us what you are trying to do?

i have two custom posty type, A and B. They are in a relationship One (A) to Many (B). When i delete the post A, i want that also all the post B that are in relationship will be deleted.

#2133865

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there,

you'll need to add some code to automatically delete the child posts when you delete a parent.

Please see this recommended solution (you'll need to adjust the slugs for your post types and relationship): hidden link

#2133875
Schermata 2021-08-04 alle 17.05.13.png

Thx for you message. I have used your code, but it's not cancelling the child! I have noticed that it's there and that relationship is disabled!

#2133885

My issue is resolved now. Thank you!

#2133897
Schermata 2021-08-04 alle 17.41.09.png

Hello,
i have discover that when i delete the post A, in my case "Intervento", other relationship with it will get broken.

Let me explain better A is in relationship with B, C, D... now the function you give me work like a charm... post B will be deleted great.
But post C, that was in relationship with A, now can't anymore be related to A.

See my picture.

#2134453

Hello,

Your screenshot does not show any related item.

Please elaborate the questions with more details:

other relationship with it will get broken.

Which one is the other relationship?
How did see it is broken?

The custom codes mentioned in:
hidden link
Should be able to delete all child "chapter" posts related with the same "book" post on same relationship "book-chapter"

#2134469

Hello,
let me explain better: i have my post A (parent) that is in relation with B (child). A is also in relation with other post C,D,E.

When i delete the post A, also post B will be deleted and that sounds great. Now i have problem with the post C,D,E that were related to A that was canceled. I can't assign anymore to any post A.

In my specific case i have post A (job), post B (work) and for example post C (worker). When i delete the "job", my "worker" relationship with "job" will be delete. Now if i want assign the "worker" to another "job" i can't anymore!

#2134549

The problem you mentioned above is abnormal, after delete post A (job), all relationships related with post A should be deleted, you should be able to setup post C (worker) with other job posts without any problem.

Please check these:
1) Make sure you are using the latest version of Toolset plugins, you can download them here:
https://toolset.com/account/downloads/

2) In case it is a compatibility problem, please deactivate all other plugins, and switch to WordPress default theme 2021, deactivate all custom PHP/JS code snippets, and test again

3) Also check if there is any PHP/JS error in your website:
https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/

#2134599

Hello,
i have tried to cancel the post A from backend and the problem will not occur.

Could be something because from frontend is not trashed but deleted directly, and i backend i have to trash first and then empty the trash?

#2135367

No, I have tried it in my localhost with a fresh WP installation, after delete the parent post with shortcode:
[cred-delete-post action='delete' onsuccess='self']Delete[/cred-delete-post]

Edit the child post again, I can connect it with other parent posts without any problem

More help:
https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred-delete-post

So there should be other problem in your website, please try as I mentioned above, upgrading plugins and check the compatibility issue in your website:
https://toolset.com/forums/topic/delete-post-in-relationship/#post-2134549