Skip Navigation

[Resolved] I need to get the parent post ID and the value of a custom field of the deleted Repeatable Group post.

This support ticket is created 2 years, 8 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 3 replies, has 2 voices.

Last updated by Luo Yang 2 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#2135377

Hi Waqar, thank you for the suggestion. I setup the "delete_post" hook, now it works, I get the output in debug.log.

My problem now is that I need to get the parent post ID and the value of a custom field of the deleted Repeatable Group post.

I tried this:

$team = toolset_get_related_post( $post_id, 'fishes' );
$fishmeasure = get_post_meta( $post_id, 'wpcf-fishmeasure', true );

But I get in debug.log zero and empty value:

$team: 0
$fishmeasure:

How can I get those values?

cheers

#2135393

Hello,

Please check the WP document:
https://developer.wordpress.org/reference/hooks/delete_post/

Take note, by the time the hook triggers, the post comments and metadata would have already been deleted. Use the before_delete_post hook to catch post deletion before that.

This action hook triggers after relationships are deleted too.

So in your case, please try the action hook "before_delete_post":
https://developer.wordpress.org/reference/hooks/before_delete_post/

#2135517

Hi Luo, thanks for the support. I replaced delete_post with before_delete_post.

Now I can get the $fishmeasure:

$fishmeasure = get_post_meta( $post_id, 'wpcf-fishmeasure', true );

But I still get zero when I try to get the Parent ID with:

$team = toolset_get_related_post( $post_id, 'fishes' );

Any suggestion?

thanks

#2137147

I have tried it in my localhost with a fresh WP installation, it works fine, I can get the parent post ID within before_delete_post action hook.

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 other 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/

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.