My site currently makes use of the code " _wpcf_belongs_post_id". I just upgraded to Types 3.0.7 (but haven't yet migrated to the new post relationships). My understanding is that this code no longer works with this Types upgrade and needs to be changed.
I'm wondering which of the shortcodes at the link below I should use—and how—to replace the above legacy code/field.
Specifically, I have been using this shortcode in a Gravity Forms merge tag.
1. Using the Form, a user creates a new custom post type and selects a city from a dropdown menu in the Gravity Form (City is the parent post type for the new post).
2. The value selected in that dropdown is then added through some Gravity Forms magic to the _wpcf_belongs_post_id field for the new post.
3. This sets the relationship in Types.
Is there a new custom field/database field that I should use? Or is more required to get this working again?
The codes at the link are API Functions, not ShortCodes.
All ShortCodes that used the hidden parent field as you show it should proceed working even if you do not replace them
The new ShortCodes for relationships is automatically inserted by the GUI when you insert it fresh, so if you would want to replace such codes you would need to use the GUI.
However, if you plan to not use those ShortCodes on NEW relationships you use then you do not need to touch it.
Migrations that are older are flagged, and stay compatible.
To know exactly what code you'd need I'd need to see your code.
>2. The value selected in that dropdown is then added through some Gravity Forms magic to the _wpcf_belongs_post_id field for the new post.
The magic that Gravity Form does, in this case, is adding the post_meta with key _wpcf_belongs_post_id and value of parent post id to the post you edit.
That will fail with new Relationships, but not with old or migrated relationships.
Instead, you need to replace the magic of Gravity forms that updates the post meta (probably update_post_meta()) and use something like toolset_connect_posts( 'posttypea-posttypeb', 5, 7 );, where you will change the 5, 7 to the ID's of posts you want to connect.
posttypea-posttypeb is the slug of your relationship or array of post types if it's a legacy relationship https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts
Thanks Beda. After doing the full migration to the new relationships system, everything displays on the front end properly.
However, there's still the issue with Gravity Forms and creating the post relationship when the form is submitted. In my Gravity Form, I use the merge tag/field, as shown in the attached screen shot. Previously, whatever city was selected in another dropdown on this form would then be merged to this City ID field, which would then create the relationship automatically when the form was submitted (by writing the ID to the "_wpcf_belongs_city_id" field.
-First, to confirm: are you saying that there's no longer any field to write the value (City ID) to?
-Or Is the hidden field "_wpcf_belongs_city_id" replaced with a different field in the new database tables?
-Or does the "_wpcf_belongs_city_id" field still exist, but I need to write something new to it, other than just the parent ID value?
I'm not sure how the new code "toolset_connect_posts( 'posttypea-posttypeb', 5, 7 )" could be made to work in this case. I need to connect the post being created with the city that was chosen in the form. Currently, I grab and store both the new post's ID and the parent city's ID using 2 different hidden fields in the form, so they're available. I just don't know how to add these numbers, which are dynamically created, to the static code above when a form is submitted.
Can you clarify? (Unless, of course, there's a different field I can use to replace the "_wpcf_belongs_city_id", in which case I'll try that.)
So - whatever Beda suggested in his reply as given under you should follow that:
The magic that Gravity Form does, in this case, is adding the post_meta with key _wpcf_belongs_post_id and value of parent post id to the post you edit.
That will fail with new Relationships, but not with old or migrated relationships.
With new relationships, you'd need to use https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts.
This does not require anymore any code that updates any meta of a post.
Instead, you need to replace the magic of Gravity forms that updates the post meta (probably update_post_meta()) and use something like toolset_connect_posts( 'posttypea-posttypeb', 5, 7 );, where you will change the 5, 7 to the ID's of posts you want to connect.
posttypea-posttypeb is the slug of your relationship or array of post types if it's a legacy relationship
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts