I have a repeater field called slides. In it I have slides, that each have a title and an image. These slides get added to a page as a slideshow. Not terribly complicated.
I need to add an id or random string to each slide, so I can jump to the slide based on a url:
Will jump to the 5th slide that has the id of a1b2c3.
I have the code to do the slide selection. Now I just need help adding an id to each custom field.
I can’t use the slide number, as it’s stored in the database, because the order might change. I can’t use the title or image id, because they might change.
Any suggestions on how to add a unique id or string to each repeater field? Thanks!
Thanks. That’s actually the first thing I tried. The problem with those solutions is the “id” changes if you change the order. I want to link to a slide (my sub_field), even if I change the order.
I looked at the template for making an addon. It seems like making a unique id custom field would be very easy.
Here you go:
I think I changed all of 4 lines 🙂
EDIT: Never mind, I then realised I had to do that myself in the php 🙂 All good.
I’m sorry to be such a noobie, I’ve added the plugin, activated it, and upon pressing “Update” a unique id gets generated for each repeater row. However, how do I now create a hyperlink to that specific row? The unique id does not seem to have been added anywhere to the DOM?
The topic ‘Add an arbitrary id to each repeater instance’ is closed to new replies.
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!
© 2022 Advanced Custom Fields.