Tell us what you are trying to do? Can I export custom post type data also contain post relationship field to csv . If yes ,which plugin/add-on can I use and how much does the it cost?
Is there any documentation that you are following?
No.
Is there a similar example that we can see?
No
What is the link to your site?
hidden link
Hello, I'm not aware of any 3rd-party plugins that will export post relationship information automatically. When exporting post data from the standard WordPress > Tools > Export tool, the related post details are included automatically. This file format is a type of XML though, not CSV. You would need some conversion process to convert that file from XML to CVS automatically.
If the export plugin you choose allows custom PHP functions to create dynamic export fields, you can use the post relationships API to insert the related post information in the export document automatically. For example, WP All Export Pro allows you to use custom PHP functions to create dynamic fields in the export document.
https://www.wpallimport.com/upgrade-to-wp-all-export-pro/
I explained how to use the post relationships API in a custom function to export information about related posts with WP All Export Pro in another ticket here in the forum:
https://toolset.com/forums/topic/export-custom-post-type-data-and-related-repeatable-field-group-data/
In that example, the User is trying to export repeatable field groups (RFGs) and include information about their parent post. This is similar to exporting information about child posts in a O2M post relationship with another post type. If your post types are connected in a one-to-many post relationship (O2M), this example is very similar. If you have a different type of post relationship, like M2M for example, the setup is a bit different.
I could set up a similar example for you if you tell me more about the post relationship, and the post type you are trying to export.
- What type of post relationship is involved here - One to One(O2O)? One to Many (O2M)? Many to many (M2M)?
- Which post types are included in this relationship? What are the slugs of these post types?
- What are the roles of each post type - which is the parent and which is the child? You can find this information by editing the relationship in Toolset > Relationships. Check the checkbox "I understand that changes to these settings may delete post associations in this Relationship" and click "Edit settings" to see this role information.
- Which post type would you like to export?
Sorry for the late reply. I have a 2 Post types.
I have already installed wp all Export pro plugin
The first one is province and the second is a district.
A province can have many Districts so it's a one to many relationship(02M). I want to export the districts post type with the following fields
1.title
2. province title(based on the post relationship)
Okay just to be clear, usually post titles alone are not enough to enable importing these posts in another site. Normally you need unique identifiers like post IDs or GUIDs. If you're exporting for a different purpose, then obviously whatever information you want to include is fine. For something simple like this you could probably use Views to generate this information, then copy + paste it into a simple text file and save that with a .csv extension. A View is usually the simplest practical approach when there is a relatively small amount of data to include, and that data can be easily output by Views using its dynamic content features. Otherwise you need to use custom PHP functions in the Export builder to fetch information from related posts.
If you want to use the exporter plugin, you'll go to wp-admin > All Export > New Export. The first step is to choose a specific post type, and choose District as that post type. Then click "customize export file" to move on to the next step. Usually ID, Title and Content are already in place in the builder. You can drag the ID and Content blocks out of the box since you don't want to include those items.
Next click "Add Field" below the builder area to add a new custom column for the Province Title. Choose the option to select a field to export, and select the ID field. You may need to reset the column name information after choosing the ID field. Check the checkbox to export a value from a PHP function, type prov_parent_title in the function name field, and paste this function in the function editor to define the custom prov_parent_title function:
<?php
function prov_parent_title($id)
{
$parent_id = toolset_get_related_post( $id, 'relationship-slug', 'parent');
$prov_title = get_the_title($parent_id);
return $prov_title;
}
?>
Replace relationship-slug in this code with the slug of your Province-District post relationship. See the screenshot here for an example.
That's pretty much all you need to configure in the builder. Continue with the remaining default configurations and generate your export. Let me know if you have questions about this.
My issue was resolved. Thank you!