How to: Sequentially Number ACF Pro Repeater Field Results in WordPress


Today I really needed to sequentially number the output of a repeater field created using the Advanced Custom Fields Pro plugin. Although this is a bit of a niche requirement, I thought I’d post the result here.

My original code, used to pull through all of the images in the photo gallery I’d set up for the current post, with their alt attributes. This is the basic usage you’ll find in the documentation:

And then my revised code, which sequentially numbers these results and gives them a class of id-number.

If you want to start the sequence from a number other than 1, you can do that by changing $postnumber = 1 to any value you like. You can of course also move the output, it doesn’t have to be used to create a unique class.


Leave a Reply


Web Design Oxford

Web Design

Google friendly, mobile optimised websites custom designed and coded onto WordPress CMS

Find out more >

WordPress Training Oxford

WordPress Training

Got a website but no idea how to use it? Book one-to-one training, or try a ‘teach and build’ session

Find out more >

Website Maintenance Oxford

Website Maintenance

Need support with an existing website but not sure where to look? Get help with updates, backups and security

Find out more >

Web Hosting Oxford

Web Hosting

Fast, reliable web hosting with scheduled backups and cPanel from just £45 per year

Find out more >