Home Forums ACF PRO Auto-populate fields after Post Object selection?


Auto-populate fields after Post Object selection?

  • Hi, is there a way to dynamically populate fields after a Post Object has been chosen?

    I had a ‘documents’ Flexible Content area that could be added to pages. This contains a repeater field which allows users to add sinmgle documents. Each document’s details ACF fields were Title, description, publisher name, published date and a file upload.

    We now want a new Documents section of the WordPress admin. I’ve created a documents CPT so that each new document now has it’s own page I can link to. It uses exactly the same fields.

    What I have done is when a user adds a document to the existing documents Flexible Content area on a page they have the option of either entering the document’s details as usual (the document doesn’t have it’s own page and does not interact with the Documents CPT) or the user can select a document from the new Documents CPT (using the Post Object field).

    What I would like is that when a Document Post Object is chosen is that the ACF fields in this section are populated from the fields in the CPT Document. Is this possible?

    1. Inside repeater field a Document is selected from Post Object field showing all Documents in CPT.
    2. Once selected, get fields from this Document’s Post Object.
    3. Overwrite fields in the repeater field with these CPT fields.

    I hope that makes sense. Is it possible? I just want to site administrator to see that they’ve chosen the right document and to save them typing out these fields again.



  • Yes it is, but it is complicated and not well documented.

    You need to add custom JavaScript. You’re script will need to fire an action when the post object field is changed. This action will need to make an AJAX request to get the information for the post selected and then populate the other fields with the data returned by the request.

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

You must be logged in to reply to this topic.