Home › Forums › General Issues › Prepopulate Custom Fields Based off of Taxonomy › Reply To: Prepopulate Custom Fields Based off of Taxonomy
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.
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 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.