Skip Navigation

[Resolved] CSV or XML Import and Export of Custom Post Types and Views

This support ticket is created 7 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.

Our next available supporter will start replying to tickets in about 2.06 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 8 replies, has 3 voices.

Last updated by pedro.S 7 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#578755

We'd like to offer our users the ability to export custom reports from our system in XML or CSV that contain values from custom post types as well as across their hierarchal relationships.

An example of the type of report we'd like to export is show in the View at hidden link where Parent data is listed for the Booking post type alongside the data of its Grandparent and even its Great-Grandparent.

We'd also like to allow our customers to bulk import field values for custom post types if possible.

I've looked into your import and export features but am unable to see if it would make above possible - can you advise?

If this isn't possible with standard Toolset features, could you let me know if CPTs would work with a plugin such as the one at hidden link ?

#578778

A little more searching and I found what will likely be the solution for import (https://toolset.com/documentation/user-guides/how-to-import-content-into-wordpress-using-csv/import-csv-ultimate-csv-importer-plugin/)

Regarding export, could you let me know if the plugin at the link below (made by the same company) would work with CPTs and Types custom fields? Also, do you know if it would be able to export details of parent or grand-parents for the post type being exported?

hidden link

#578899

Dear Jon,

Yes, you are right, there is a document "How to import data from a CSV file using the WordPress Ultimate CSV Importer plugin":
https://toolset.com/documentation/user-guides/how-to-import-content-into-wordpress-using-csv/
It introduced two plugins:
1) The Pro version of the WordPress Ultimate CSV Importer plugin
2) The CSV Importer plugin

Both of them are not Toolset plugins, they are not the products of our company.

And they can not import the parent/child relationship, Types plugin is using a custom field "_wpcf_belongs_{parent-slug}_id" to store the parent post ID, in difference websites, the parent post IDs are different, so you will need to setup this custom field value manually. see our document:
https://toolset.com/documentation/customizing-sites-using-php/displaying-child-posts/
section "Displaying child post contents"
Please note the key argument _wpcf_belongs_writer_id in the meta_query property. The writer part is the slug of our parent post type. If you were listing the children posts of a “House” post type, you would use _wpcf_belongs_house_id.

#579467

Okay, I have looked through a few more plugins and found that WP All Export allows for custom php queries to be used to access data (details at hidden link).

With that, do you think it would be possible to Query Parent, Grandparent and Great-Grandparent data during export of a Custom Post Type?

#579737

As I mentioned above:
in difference websites, the parent post IDs are different, so you will need to setup this custom field value manually.

I don't think "WP All Export" will be able to setup the Grandparent and Great-Grandparent data automatically.

#579766

I understand that the fields will all have to be set up manually, my question is: is it possible to create a php query that can get that grandparent data for a post?

#579795

As I mentioned above, Types plugin is using a custom field "_wpcf_belongs_{parent-slug}_id" to store the parent post ID,
https://toolset.com/forums/topic/csv-or-xml-import-and-export-of-custom-post-types-and-views/#post-578899

So in a single child post you can get it's parent post ID with WordPress function get_post_meta(), for example, the parent post type is using slug "house", then you can get it's parent "house" post ID, like this:

$room_id = get_the_ID();
$house_id = get_post_meta(get_the_ID(), '_wpcf_belongs_house_id', true);

Same as above, you can get the grand parent post ID.

Here is a document about "Displaying Fields of Grandparents"
https://toolset.com/documentation/user-guides/displaying-fields-grandparents/

For your reference.

#581054

I have successfully tested getting grandparents and great-grandparents through php now with help of your code, thanks!

#1122630

Hi,

JonB would you mind sharing how did you achieve to do this?

thanks