Home Forums General Issues Prepopulate Custom Fields Based off of Taxonomy Reply To: Prepopulate Custom Fields Based off of Taxonomy

  • Hi @johnstew

    As I said before, modifying it using JS would be a complex thing to do. This is what I have in my mind (and tested it in the console):

    1. Target the add row button and execute the .click() function.
    jQuery(".acf-field-1234567890abc .button-primary").click()

    2. Search the last generated row that has data-id that is not equal as “acfcloneindex”.
    jQuery(".acf-field-1234567890abc .acf-row[data-id!='acfcloneindex']:last input[id$='field_abc1234567890']").val("test")

    “field_1234567890abc” is the key of my repeater while “field_abc1234567890” is the key of the subfield.

    Regarding the second method, yes, you can get the latest four entities in that hook. It should be the same as the one in your PHP code.

    The add_row() function will only work if the reference key exists in the database. It means that you have to save the post from the backend. If you use the update_field() function, you can pass the field key instead of the field name to create the reference key in the database. But I guess it doesn’t matter as you do it on the backend anyway. It may be odd, but the update_field() function can be used to create a new custom field entries too.

    I hope this makes sense 🙂