Pagination with Gallery field – Advanced Custom Fields

If you work a lot with WordPress, I’m sure you are familiar with the plugin Advanced Custom Fields (ACF). If not, you better go check it out, as this is absolutely one of the best plugins out there. With the PRO version you can use repeater, gallery and flexible content field. Woohoo!

Repeater field and gallery field, are really awesome. There is one thing tho – there is no pagination for that. But don’t worry, as there is a solution for that!

Pagination for gallery field

The pagination for gallery and repeater are a bit different, so I will start with the solution for gallery field. First thing you need to know – even tho pagination will not be generated by some magic function in WP – if you add “number” to the end of the url, you can get current pagination number with “get_query_var(‘paged’)“. Simple as that. And for pagination you can use WP function paginate_links.

Here is full code:

In case you want just “load more” button, instead of “paginate_links” you could do something like that:

For the next/prev buttons only:

Bonus code – Pagination with internal filter/categories

Update 24.04.2016

If you want to divide gallery into categories or something, and you want to have custom subpages for each category, you will have to add some rewrite rules. Everything started after comment from Manhattan and some emails we exchange to resolve this. Long story short I present you a gist where you can find details about this solution.

  • Share it on Twitter
  • Share it on Facebook
  • Share it on Pinterest
  • Share it on Google+
  • Share it on LinkedIn

Comments (15)Add comment

Take part in the discussion

Use pastebin.com or jsfiddle.net to add your code snippets
Your email address will not be published.