Skip Navigation

[Resolved] How to import posts with post relationships?

This thread is resolved. Here is a description of the problem and solution.

Problem:
With the changes in Types 3 the post relationship is no longer stored as post meta but in custom tables. How to import posts and maintain the relationships?

Solution:
There is a new solution to set up relationships when importing posts, described in the documentation.

Relevant Documentation:
https://toolset.com/documentation/user-guides/importing-content-from-csv-with-post-relationships/

This support ticket is created 6 years, 5 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
- 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 8 replies, has 3 voices.

Last updated by Ed 6 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#909364

Ed

With previous post relationships, the custom fields were something like "wpcf_belongs_XXXXXX_id". Have they changed and, if so, what are they, now?

#909376

There are no more custom fields now, unless in migrated Relationships posts.

The new relationships are stored in Custom Database tables, and the data can be accessed with the new API:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

#909813

Ed

So, there's no longer a way to import posts, in bulk, and have their relationships already set? Each CPT relationship has to be set, manually?

"Toolset Helps You Build Advanced WordPress Sites Without Programming" <-- I'm just sayin'...

#910526

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

This has actually seen a significant improvement with Types 3.0.

Before importing related posts was problematic because if you wanted to set the _wpcf_belongs_parent-slug_id field on a child post you needed to know the parent post ID and if you were importing a whole series of both parent and child posts at the same time the parent posts had not already been created and so their ID was unknown. That required one of various workarounds to be used when importing.

Now we have added a two-part migration tool for related posts which includes a batch job that makes all the connections automatically for you in a single import.

Please see the documentation here: https://toolset.com/documentation/user-guides/importing-content-from-csv-with-post-relationships/

#910533

Ed

Great!

Just knowing that it can still be done is a huge comfort. It doesn't look like I'll have a problem figuring this out.

Thanks for the info!

PS: I'd still be interested to know if relationships could be set using custom form fields (GravityForms), when a user submits a listing. That may be another ball of wax, completely.

#910624

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Ed

Relationships are no longer stored as post meta but in custom database tables instead.

The only way to set and retrieve relationship info is via the API, so you would need to use a hook when a Gravity Form was submitted and then use the tooset_connect_posts function to set the relationship.

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

#911069

Ed

One last question...

Can I safely update my older sites, without the legacy relationships being jacked up?

#911070

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Internally there is a switch that operates across the whole of Toolset as to whether the migration wizard has been run or not.

You can upgrade your existing sites and not run the migration wizard and everything will continue to work as before.

Then there is a compatibility layer so that if you *do* run the migration wizard your existing relationships should continue to work as before, although if you were to edit a form and auto-generate the markup the format of the relationship fields would change, for example.

My advice is to update, but only run the migration wizard if you are actively developing the site and want to take advantage of some of the new relationship features.

#911071

Ed

Thanks, Nigel (and Beda). I appreciate the info!