is there anyway to fill out the repeater fields automatically? I want to use 10 repeater fields for each post where the caption for each image is the same. I am wondering if there is anyway I could just upload all 10 images at once without having to upload each image separately. The reason I want to do that is because I want to use this code: http://www.advancedcustomfields.com/resources/tutorials/querying-the-database-for-repeater-sub-field-values/
What I’m trying to achieve is this:
I am creating a site for a friend. The site is a research library. Each post consists of scientific data and 10 graphs/data plots. In each post there is going to be 10 links with pre-defined titles (the same for each post) linking to the 10 images.
I could add those 10 images manually, but there’s over 200 posts so looking for a way to speed things up. I’m thinking I can query the db for the sub field value (caption) and use the captions for the links, assuming I could add all images at once and have default values for the captions/titles. I would try something like this:
<ul> <img src="<?php echo $src; ?>" /> <li> <a href="<?php get_permalink( $row->post_id ); ?>"> <?php echo get_the_title( $row->post_id ); ?> </a> </li> </ul>
I want to have a link to each image (opening in a lightbox) with the pre-defined title… Not sure if it would work or if maybe could do so with the gallery add-on. If not maybe you could point me in the right direction.
Good description, however, I am a bit lost due to not seeing the repeater field in question. Can you post some screenshots to help me see and understand how you want the data to automate?
My first idea is to hook into a WP action which is fired when WP creates an autosave post (when you first edit a new post). Your function could then just insert the default values and then when the page loads, your default values will exist!
Thanks for the reply and sorry about that, a bit hard to explain. Will try again.
Each post will have several sections, and one of the sections will consist of 10 links each linking to a chart/image. While the images/charts will be different for each post, the titles for the links will be the same in every post.
So I would have a section like this:
While the titles to the links opening the images in a lightbox will be the same in each post, the images will be different.
So Ideally I would have some sort of solution to where I could just upload all images at once. Then each image would be matched with the corresponding title (pre-defined title 1 to image 1, pre-defined title 2 to image 2, etc.), and I’d use a function to display the image links through the template used for my custom post type.
I hope that makes sense, if not I’ll try to put together an example tomorrow morning.
Thanks a lot for your help 🙂
I’m starting to understand the question but again, I have too many questions regarding the repeater field and what exactly you are trying to do.
Screenshots will help.
Heres some info:
1. You can upload multiple images at once using the repeater field.
2. If all your titles are pre-defined, why put them into a field, why not put them into the template?
I would definitely not add the text into the backend. Instead, I would add it to the front end template.
Tip: change the repeater field layout to ‘table’ to streamline the image / file columns.
You can then upload the 10 images and 10 files at the same time.
Then in your template, you can loop through the rows of data and use the row index (counter variable $i) to find the corresponding label (labels stored in an array in the template file).
Then you client just needs to order the images correctly in the back-end. Easy
Tip: Look at the code and run through it as if you were the computer reading the code line by line. Does it work the way you want it? Even use a pencial and paper approach to write out the output
Thanks elliot, you’re right, putting it in the while loop doesn’t make sense. Have been going on too little sleep lately… Thanks for all your hard work and support, buying the add-ons and using your plugin has been life saver!
You must be logged in to reply to this topic.
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!
© 2019 Advanced Custom Fields. Subscribe