Skip Navigation

[Resolved] Add and manage new relationship with ancient relationship system

This support ticket is created 4 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 7 replies, has 2 voices.

Last updated by Shane 4 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#1770899

Tell us what you are trying to do?
The site use the old relationship system since 4 or 5 years.
I have just added a new relationship and i want to programmatically add a connection between two posts. The child post-type is mail-confirmation and the parent post-type is defi

I have tried to use the old code I am using for other relationships on the site.
It consists in adding a post_meta _wpcf_belongs_defi_id to the child post.
something like this :
update_post_meta($child_id, "_wpcf_belongs_defi_id", $id_defi);

but it doesn't work.
I have also tried to use the new function toolset_connect_posts but it doesn't work either.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?
hidden link
the part of the site concerned is password protected.

#1771209

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Matthias,

Thank you for getting in touch.

Have you ran the migration for the new relationship settings ? If not then can you go to Toolset -> Relationships and run the migration. If you haven't ran the migration then you will be presented with the option to do it. If you've already done this then you will see the option to create a new relationship as well as your existing relationships.

Please let me know so that I can best advise on how to resolve this.

Thanks,
Shane

#1771347

Hi Shane,

Thank you for your answer.

If I run the migration, will I have to do changes in the code for the old relationships already created ?
For example can I still connect parent and children by adding a meta (_wpcf_belongs_[parent]_id) to the child post ?
Or another example, can I still use the function wpcf_pr_post_get_belongs ?

Thanks,
Mat

#1771353

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Matthias,

No once the migration has been done all your relationships will be updated to the new method, so you will need to make use of the new functions in our documentation to below to set the relationships programatically.

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

Please let me know if this helps.
Thanks,
Shane

#1771653

Hi Shane,

Thank you for this explanation.
I don't want to change the code for the previous relationship.

Is it possible to keep the old system (no migration) and create new relationship using the old system ?
Or new relationships necessarily use the new system ?

Thanks,
Mat

#1772231

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Matthias,

If you don't perform the migrations you will need to use the old methods, however you won't have access to the new features in Types such as the Repeatable Fields Groups. Also features from our Toolset blocks on how it handles gathering of relationship data won't work.

So you are not able to use a combination of the Old and New system as the database structure will be different.

Thanks,
Shane

#1773163

Hi Shane,

Thank you for this precision.

So to go back to my initial question : I didn't do the migration, so I should be able to use the old system.
But I created a new relationship and the code I was using before doesn't work :

"
It consists in adding a post_meta _wpcf_belongs_[parent]_id to the child post.
something like this :
update_post_meta($child_id, "_wpcf_belongs_[parent]_id", $id_parent);
"

Any ideas on why it doesn't work now with this new relationship ?

Thank you,
Mat

#1773409

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Matthias,

You code to update the field is correct, however what I recommend is that you check to see if the $id_parent value is getting populated as well as that the $child_id value is the correct one for the post you are updating.

To check this you can dump their values onto the page using the var_dump() function.

Example


var_dump($id_parent);

When you do this you should see the raw value of the field being shown on the page that this code is being run on.

Thanks,
Shane