This function will use the default "jet_rel_default" table in JetEngine to look for the post_id of the parent and return its relations from the "child_object_id" column. If you're using a separate table for your relations, you can change the $table_name value.
- Add a New Field in WP All Export (see https://d.pr/i/OW9dze).
- Set a name for the column and use "ID" for the field to export (see https://d.pr/i/v5Mq98).
- Modify the function as needed, paste it in the Function Editor and paste the name of the function in the "Export the value returned by a PHP function" field (see https://d.pr/i/2c6c07).
- The function will return a list of IDs separated with pipes by default, but if you want to export the titles instead, you need to change the $mode in "function my_export_je_relation ($post_id, $mode = 'id')" to "title".
// Change "id" for "title" if you need to export the titles instead of IDs
function my_export_je_relation ($post_id, $mode = 'id') {
global $wpdb;
// The "jet_rel_default" table is the default JetEngine value, if your using a custom DB table for relations, change it here
$table_name = $wpdb->prefix . "jet_rel_default";
// Fetch child object IDs related to the parent post ID.
$child_ids = $wpdb->get_col($wpdb->prepare("SELECT child_object_id FROM $table_name WHERE parent_object_id = %d", $post_id));
// Default behaviour is to return the ID, but you can change the mode to "title" to export titles instead
if ('title' === $mode) {
// Get relations titles by ID
$titles = array_map(function($id) {
$post = get_post($id);
return $post ? $post->post_title : '';
}, $child_ids);
return implode('|', $titles);
}
return implode('|', $child_ids);
}