Skip Navigation

[Resolved] relarionship does not work when deleting custom post entry

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

Last updated by kostasO 3 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#1682413

Hi,

am using toolset relationship one to many (one = album, many = tracks).

When i am creating a new post on hook cred_save_data , i am seraching all the chlidren posts with the following code

$relationship = 'my_relationship';
$param = '@' . $relationship . '_parent';
$parent_id = $_REQUEST[$param];
$child_posts = toolset_get_related_posts($parent_id, $relationship, array(
'query_by_role' => 'parent',
'limit' => 999,
'return' => 'post_object',
'role_to_return' => 'child',
));
$child_posts[] = get_post($post_id);

it works perfectly!

I am trying to use the same code on the hook
before_delete_post to find the $parent_id ( i am not using forms to delete the post, I am doing it from the dashboard ) and the function that I call on this action has input only the $post_ID

$relationship = 'my_relationship';
$param = '@' . $relationship . '_parent';
$parent_id = $_REQUEST[$param];

but I am getting the error

PHP Notice: Undefined index: @album-collection-target_parent ....
PHP Fatal error: Uncaught InvalidArgumentException: All provided arguments for a related element must be either an ID or a WP_Post object ...

pointing to a line of code --> $parent_id = $_REQUEST[$param];
if I have understood correctly the error is coming from here $param = '@' . $relationship . '_parent';

so my ---------------- QUESTION is -------------------------

how to find the parent of a post when i have the post_id

#1683325

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Another way to fetch the related posts using the post relationship is using the WP_Query as demonstrated with the following doc:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/

Can you please try to use that and let me know if that works. If no: then I will require problem URL where you are trying to delete the entry as well as access details and please tell me where you added the existing code.

*** 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.

#1692389

My issue is resolved now. Thank you!

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