Title: Exporting bidirectional relationship fields
Last modified: October 28, 2022

---

# Exporting bidirectional relationship fields

 *  Resolved [Halit Ayarcı](https://wordpress.org/support/users/doktorramiz/)
 * (@doktorramiz)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/exporting-bidirectional-relationship-fields/)
 * Hello,
 * I have a film blog. I use birectional fields to link the actors and films.
 * When I tried to export the films, the film_actors field which is a relationship
   field exports an array instead of the names of the actors.
 * I tried WP Imp Exp Lite and WP All Export plugins.
 * I am an ignoramus about PHP by the way. This is a hobby blog.
 * Does anybody have an idea how to solve solve this?
 * Thanks

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Support [pdclark](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/exporting-bidirectional-relationship-fields/#post-16146065)
 * The below PHP, when installed as a plugin, will export post type “page” with 
   IDs for relationships stored in field “film_actors”:
 *     ```
       <?php
       /**
        * Plugin Name: Pods — Relationship Export
        * Description: Export a post type to CSV with <a href="admin-ajax.php?action=export-relationship">this link</a>.
        * Plugin Author: 𝜑δ•ℂᴹ
        * Author URI: https://pd.cm/
        * Version: 1
        */
   
       add_action(
       	'wp_ajax_export-relationship',
       	function(){
       		global $post;
   
       		$post_type = 'page';
       		$relationship_field_key = 'film_actors';
   
       		header( 'Content-Type: text/csv' );
       		header( 'Content-Disposition: attachment; filename=' . $post_type . '.csv' ); 
   
       		$query = new WP_Query(
       			[
       				'post_type' => $post_type,
       				'posts_per_page' => -1,
       				'post_status' => 'publish',
       			]
       		);
   
       		ob_start();
       		$output = fopen('php://output', 'w');
   
       		$headers = [
       			'ID',
       			'post_title',
       			'post_content',
       			$relationship_field_key,
       		];
   
       		fputcsv( $output, $headers );
   
       		while ( $query->have_posts() ) {
       			$query->the_post();
   
       			fputcsv(
       				$output,
       				[
       					$post->ID,
       					$post->post_title,
       					$post->post_content,
       					implode( ',', (array) get_post_meta( $post->ID, $relationship_field_key, false ) )
       				]
       			);
       		}
   
       		fclose( $output );
   
       		echo ob_get_clean();
   
       		exit;
       	}
       );
       ```
   
 * Once uploaded as a plugin, a link to download the CSV displays in the plugin 
   description.
 *  Thread Starter [Halit Ayarcı](https://wordpress.org/support/users/doktorramiz/)
 * (@doktorramiz)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/exporting-bidirectional-relationship-fields/#post-16153652)
 * Thank you Paul

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Exporting bidirectional relationship fields’ is closed to new replies.

 * ![](https://ps.w.org/pods/assets/icon.svg?rev=3286397)
 * [Pods - Custom Content Types and Fields](https://wordpress.org/plugins/pods/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/pods/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/pods/)
 * [Active Topics](https://wordpress.org/support/plugin/pods/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/pods/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/pods/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Halit Ayarcı](https://wordpress.org/support/users/doktorramiz/)
 * Last activity: [3 years, 7 months ago](https://wordpress.org/support/topic/exporting-bidirectional-relationship-fields/#post-16153652)
 * Status: resolved