Home › Forums › Add-ons › Repeater Field › Add an arbitrary id to each repeater instance
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:
/slideshow/a1b2c3
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.
The unique id addon is done. Is there somewhere I can put it online for other people who might need it?
+1 for this.
Id be very interested in looking into how you’ve built this addon.
Can you perhaps provide a link to github?
Here you go:
https://github.com/gelform/acf-unique-id-field-type
I think I changed all of 4 lines 🙂
Here a version for ACF V5.
https://github.com/KLicheR/wp-acf-unique_id
EDIT: Never mind, I then realised I had to do that myself in the php 🙂 All good.
Hi @KLicheR,
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?
Thanks,
Mar
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.