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