Support

Account

Home Forums Add-ons Repeater Field Issues with repeater…

Unread

Issues with repeater…

  • Hello,

    I’m using a repeater because I need to store a list of files for a given CPT.
    First of all I hope this is a good idea and maybe there’s an easiest wat to do ? I don’t know.
    I just need to store an undefined number of files, which means the admin can upload how many files as he wants. But I wasn’t able to do it without repeater…

    So if you think it’s possible without repeater, I’d like to know how 🙂

    Second question : I’m not sure I understand how to add some files inside the repeater programmatically…

    I tried different things but nothing works.

    
        // First we need to retrieve the key of the 'document' field
        while (have_rows('documents_client', $quoteId)) {
            the_row();
            $subField = get_sub_field_object('document');
            $documentFieldKey = $subField['key'];
            break;
        }
    
        // Let's retrieve the existing rows
        $rows = [];
        while (have_rows('documents_client', $quoteId)) {
            the_row();
            $row = get_row();
            if ($row) {
                $rows[] = $row;
            }
        }
    
        // Now let's add a new document
        $attachmentId = 240;
        $rows[] = [$documentFieldKey => $attachmentId];
        update_field( 'documents_client', $rows );
    

    Can you please help me and tell me what’s wrong in my code ?
    For now I’m trying to add the attachment 240 but then it will be dynamic.

    Regards

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.