• Resolved Sea Jay

    (@jcollier)


    We would like to store multiple text entries in a repeating field be stored with a delimiter (such as |) rather than in a serialized array so we can easily export the data in a single field via WP Sheet Editor.

    We see the options to change the display format, but that doesn’t seem to change the storage format.

    Is there a configuration option to make that change?

Viewing 1 replies (of 1 total)
  • Plugin Support pdclark

    (@pdclark)

    There is not a user interface to change the storage format.

    There is a save hook, which can be used to write another field value based on the value of the repeating field: https://docs.pods.io/code/action-reference/pods_api_post_save_item/

    The following plugin will cause a repeating text field named multiple_text_entries to be saved as pipe-separated values in field multiple_text_entries_pipe_separated when the post is saved:

    <?php
    /**
    * Plugin Name: Save field as pipe-separated values
    * Description: Saves a repeating text field as a pipe-separated string when saving.
    */
    add_action(
    'pods_api_post_save_pod_item',
    function ($pieces, $is_new_item, $id ) {
    $repeating_field_name = 'multiple_text_entries';

    if ( array_key_exists( $repeating_field_name, $pieces['fields'] ) ) {
    $entries = $pieces['fields'][ $repeating_field_name ]['value'];
    if ( ! is_array( $entries ) ) {
    $entries = [ $entries ];
    }

    $entries = array_map( 'trim', $entries );
    update_post_meta(
    $id,
    $repeating_field_name . '_pipe_separated',
    implode( '|', $entries )
    );
    }
    },
    10,
    3
    );
Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.