Hi Pete, it’s been a while and I never fully used this functionality. I think I only figured out how to add a repeater row with Jquery. The problem was that removing the row triggers a confirmation dialogue box, which you also would have to ‘click’ using JS.
// Add data to ACF field with Jquery
(function($){
if (typeof(acf) == 'undefined') { return; }
var repeatDiv = document.querySelector('.acf-field-asdfkey');
var addRow = repeatDiv.querySelector('.acf-button');
addRow.click();
var field = acf.getFields({
key: 'field_asdfkey'
});
field.slice(-1)[0].val(gridArea);
})(jQuery); }
I don’t really know if this code still works, but it’s all I have. Hope it can be of help.
I didn’t find a proper solution, but I found a way around it on Stackexchange: See the answer here: https://wordpress.stackexchange.com/questions/331774/load-script-after-block-is-inserted?rq=1 (basically onload event on an empty image….strange, but it works).
Thanks very much, John. I already figured out how to add a repeater row, but I wasn’t sure how to deal with removing (because of the confirmation popup). Your code is very helpful.
I won’t be adding and removing at the same time, they’re separate actions. But it’s good to know there’s a workaround.
I know this is a bit of an old topic, but I’m having the same problem and your link no longer works @hube2 .
Did you eventually figure out how to (easily?) add a repeater row in Javascript?
This was exactly what I was looking for, had the same question. Just one thing: Your method has as a downside that it now loads on every post editor, even if the specific block for which the style or script is is not used.
Is there a way to make it conditional on a specific custom ACF block being used?
Thanks James, that helped me get started.
Hi James, I know this is a bit of an old topic, but this seems to be exactly what I was looking for.
My basic template works, but I’m getting a bit stuck on how to get those post IDs into the url (basically how to get users to select the product that is to be compared and send them to the right URL with the correct Post IDs).
Would you be able to give me some pointers of where to start looking for a solution?
Thanks! Rob
UPDATE: Actually already figured it out, I used the TRUE/FALSE ACF field with an IF statement inside the link’s class.
<div class="link-item <?php if( get_sub_field('featured_link') ): ?> <?php echo 'featured'; ?><?php endif; ?>">
I’ve found this link which describes the basic process: https://aball.co/news/create-a-custom-post-in-wordpress-using-zapier/
That’s the best I’ve found so far, maybe it helps you.
I see, I heard about WP All Import before, good to hear it works well with ACF. It would be more of an informational site about products, so I’m not using Woo. The repeater field sounds like the way to go.
However, I’d like to have an external database which, if updated, automatically updates the info on WP, instead of manually importing a CSV file each time. Do you have recommendations of a solution that works well will ACF? Or will it have to be a custom coded solution in any case?
Thanks for the help.
Thanks John, that’s helpful. I’m looking to populate my custom fields based on an external database (each post is a product, each custom field is an attribute of a product). Is it possible to use a repeater field for this purpose?
I can understand how it automatically adds a new field if you edit the information in manually, but how would it work if I’m adding in the information automatically from a database? (taking into account that the number of URLs per product will vary and may be added to later)
Did you ever found out how to make this work?
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.