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 ?
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
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.
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?
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.
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?
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.
I have successfully tested getting grandparents and great-grandparents through php now with help of your code, thanks!
Hi,
JonB would you mind sharing how did you achieve to do this?
thanks