Hi Nigel,
you are right. It is working now as expected.
Thank you so much, I really appreciate your support.
Kind regards
Lara
Hi Nigel,
I am truely sorry for reopening the thread again. I did further testing today and I observed that ..
<?php
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
/**
* Reset parent post ID on post edit form
*/
function ts_override_parent( $form_data ){
$form_id = '4787';
if ( $form_data['id'] == $form_id ){
error_log('object: ' . print_r($_POST, true));
// reset parent
$_POST['@buchungssystem-selbstportrat_parent'] = '4668';
$_POST['@selbstportrat-element-portrat-user_parent'] = '4702';
}
}
add_filter( 'cred_before_save_data', 'ts_override_parent' );
It's weired the following piece works
$_POST['@buchungssystem-selbstportrat_parent'] = '4668';
but this part, will not be changed
$_POST['@selbstportrat-element-portrat-user_parent'] = '4702';
I don't know, I'm sorry. Can this problem be solved?
Kind regards
Lara
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
Sorry Lara, the private site credentials are automatically removed when a thread is resolved.
Can I ask you for them again?
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
Hi Lara
You can close the other ticket, I'll work out what the issue is here.
It's easier for me to do testing locally, so I'm going to install a copy of your site locally and debug what's happening there, and then I'll update you again here.
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
OK, I think I identified the problem to the slug of the second parent post selector in the $_POST object being different than I expected.
I've made what will hopefully be the final edit to the code, as follows:
<?php
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
/**
* Reset parent post ID on post edit form
*/
function ts_override_parent( $form_data ){
$form_id = '4787';
if ( $form_data['id'] == $form_id ){
// reset parent
$_POST['@buchungssystem-selbstportrat_parent'] = '4668';
$_POST['@selbstportrat-element_parent'] = '4702';
}
}
add_filter( 'cred_before_save_data', 'ts_override_parent' );
That is live on your site, if you could test one more time please.
Thanks for your patience.
Hi Nigel,
many thanks for your patience and hard work with that issue too.
Also many appologies for the delay.
I will close the other ticket.
I'm stuck in another project, but I will test the issue tomorrow evening.
I'm so sorry for the delay.
Kind regards
Lara
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
OK, let me know when you have tested, fingers crossed it goes okay.
Hi Nigel,
I tested and this is the result:
## 1
$_POST['@buchungssystem-selbstportrat_parent'] = '4668';
This is fine 🙂
## 2
$_POST['@selbstportrat-element_parent'] = '4702';
Here, we have now the following situation: The first choice ('4703' - page) is removed. But the second choice ('4702' - page) is not connected. Right now, there is no page connected in the 'selbstportrat-element_parent'-relationship, after submitting the form.
Kind regards
Lara
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
I'm really sorry, Lara, but it's not very easy to test.
There is only one post on the site I can test with ("Night Owl"), and once I've used the edit form once, I can't use it again.
So I've edited the template for displaying the Selbstporträt posts so that it just displays the edit form directly each time (on my local copy of your site), so I've been able to submit multiple tests.
And... there is a simple error in the code I gave you.
The cred_before_save_data hook is an action, but I've added it as a filter.
I'm surprised it worked at all (it would have been easier to debug if it hadn't) rather than half-worked.
This should be the final version...
<?php
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
/**
* Reset parent post ID on post edit form
*/
function ts_override_parent( $form_data ){
$form_id = '4787';
if ( $form_data['id'] == $form_id ){
// reset parent
$_POST['@buchungssystem-selbstportrat_parent'] = '4668';
$_POST['@selbstportrat-element_parent'] = '4702';
}
}
add_action( 'cred_before_save_data', 'ts_override_parent' );
It's definitely working on my local copy of your site, if you could please check one more time.
Awesome suppoprt, thank you so much Nigel.
Now it works perfectly.
Mistake, still works awesome 😉