Skip Navigation

[Resolved] One-to-many-relationship & Edit post form

This support ticket is created 5 years, 1 month 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 25 replies, has 2 voices.

Last updated by Lara 5 years ago.

Assisted by: Nigel.

Author
Posts
#1390165

Hi Nigel,

you are right. It is working now as expected.
Thank you so much, I really appreciate your support.

Kind regards
Lara

#1390769

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

#1391079

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?

#1392415

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.

#1392523

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.

#1392825

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

#1393063

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.

#1393883

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

#1394145

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.

#1394241

Awesome suppoprt, thank you so much Nigel.
Now it works perfectly.

#1564431

Mistake, still works awesome 😉