Trouble Persisting Repeater Field Data in Listing Update Form

Hello,

I’ve made the suggested changes by removing all serialization-related code as advised. However, despite these modifications, I’m still encountering an issue where the data does not appear in the repeater fields when updating a listing.

Here’s a summary of the situation:

  1. Problem Description: The repeater field is successfully added to the listing submission form, and I’ve confirmed that the data is being retrieved correctly from the database when attempting to populate the update form. However, the data retrieved does not appear in the repeater fields on the update form.
  2. Removed Serialization Code: I followed the recommendation to remove all serialization-related code, including manual serialization and deserialization processes. The current implementation relies on HivePress to handle data storage and retrieval automatically.
  3. Current Code Implementation: Below is the updated code for adding the repeater field to both the submission and update forms:
add_filter('hivepress/v1/forms/listing_submit', function($form) {
    $form['fields']['programme_par_jour'] = [
        'label' => 'Programme par jour',
        'description' => 'Ajoutez vos éléments ici',
        'type' => 'repeater',
        '_order' => 1000,
        '_external' => true, // Permet à HivePress de gérer automatiquement l'enregistrement des données
        'fields' => [
            'custom_text' => [
                'label' => 'Texte Personnalisé',
                'description' => 'Entrez votre texte ici',
                'type' => 'textarea',
                'required' => true,
                'min_length' => 10,
            ],
        ],
    ];

    return $form;
});

add_filter('hivepress/v1/forms/listing_update', function($form, $listing_update_object) {
    if ($listing_update_object) {
        $listing_object = $listing_update_object->get_model();

        if ($listing_object) {
            $listing_id = $listing_object->get_id();
            $programme_par_jour_values = get_post_meta($listing_id, 'programme_par_jour', true);

            // Pas besoin de désérialiser manuellement ici
            $form['fields']['programme_par_jour'] = [
                'type' => 'repeater',
                'label' => esc_html__('Programme par jour', 'text-domain'),
                'description' => esc_html__('Ajoutez vos éléments ici', 'text-domain'),
                'value' => $programme_par_jour_values,
                '_order' => 1000,
                '_external' => true,
                'attributes' => ['id' => 'programme-par-jour-repeater'],
                'fields' => [
                    'custom_text' => [
                        'type' => 'textarea',
                        'label' => esc_html__('Texte Personnalisé', 'text-domain'),
                        'description' => esc_html__('Entrez votre texte ici', 'text-domain'),
                        'required' => true,
                        'min_length' => 10,
                    ],
                ],
            ];
        }
    }

    return $form;
}, 10, 2);
  1. Debugging Efforts: Despite removing the serialization code, the issue persists. I suspect that the problem might be related to how the repeater field data is handled or saved during the update process. Additionally, I’ve explored the possibility of dynamic IDs causing discrepancies between the retrieved data and the form fields.
  2. Request for Further Assistance: I’m seeking additional guidance or insights into what might be causing this issue or suggestions for further debugging steps. Any assistance from the community would be greatly appreciated.

For reference, you can find the original post and discussion here.

Thank you for your help and support in resolving this matter.

Hi,

Sorry for the delay.

I recommend using the hivepress/v1/models/listing/attrbutes filter hook instead of 2 hooks from the code snippet you shared. It’s a high-level API that will add fields to the corresponding forms and meta boxes, also handling data validation and saving. For example, this is how the Price Extras field is added by the Marketplace extension Awesome Screenshot You can find more samples here Search · user:hivepress hivepress/v1/models/listing/attributes · GitHub