ACF Pro Repeater field array data - how to get title and URL

Hi everyone,

I have been wracking my brain following a previous Forum with the exact thing im trying to achieve. (seen here: Get specific value from acf file array )

However when I follow it i either miss some further context or info that is not shown that could help me to get said data to show.

For clarity this is a file repository/resources single post, so say a user goes in and uploads five files to this post and publishes it, it should then have five files in a list with their title (possible file size and type as well), and a link to said files (acting like a wordpress link post too).

The idea is a user uploads a few relevant files into a post (using ACF Repeater - in this case the repeater is “add_additional_files”- the user input fields which get repeated are “additional_files” for each individual entry)

[

]

Then getting the “title” and the “url” array fields to properly display Title of the file with the URL in a text field allowing the user to click directly to said file (if possible also a dynamic file size read out in the title as well e.g. .zip 7.1mb - )

Then this should output the file array to the front end, where I need help in the row, column, and text layout to set the proper consumer, provider and such at each level. Reading the article I seem to be missing something along those lines. In what should be placed where.

I appreciate any help you can give. Additional login details attached in secure note for you.

Any help you can render would be greatly appreciated. I followed the previous forum posts instructions and its still not rendering the file array correctly in that its showing the right amount of entries, but it refuses to get the file array “title” “url” etc etc

Hey @IPA_tech,

Thanks for reaching out!

The other thread is using a group field and it is not the same as your setup. To fix the issue of your current setup, I remove the first Looper Provider and Looper Consumer.

Then instead of using {{dc:looper:item}}, I replaced it with {{dc:looper:field key="add_file"}} then it fixed your issue.

Hope that helps.

Hi Marc,
Thank you so much for correcting that for me. I see where I went wrong now.

Much appreciated. One more thing how would one go about formatting the filesize output from the file array, so it shows with the proper decimal point and a max of say 2 deep decimal points (I.e: 20.85mb being the goal here).

Hey @IPA_tech,

I don’t think we could accomplish your desired outcome with your current setup. If you can update your PHP version to 8.1 or up, we can enable Twig and achieve your desired outcome.

Here’s a little overview of Twig:

Thank you.

Hi Marc,

Thank you I have since enforced PHP 8.1.9 and the theme was updated accordingly. I see Twig is a new system (to me anyway)

I hope you are able to help, thankyou.

Hey There,

When Twig is enabled, you can use Size: {{ {{dc:looper:field key="filesize"}}/1000|round(1, 'floor') }}mb. It is unavailable in your staging area because it uses PHP 7.4. Please check the secure note below:

Thanks.

Thank you so much Ruenel.

Apologies it seemed that Sitegrounds was enforcing PHP 7.4 and I had to get support to force 8.1 in the htaccess.

All seems good now, except for some further formatting. Is there a way I can remove the extra decimal points?

I added some extra values to your code so the decimal point could be moved to the appropriate spot.

image

However I want to refine it so its only a maximum of 2 decimal points after said decimal.

The slightly modified code is: Size: {{{{dc:looper:field key="filesize"}}/1000000|round(1, 'floor')}}mb

You are most welcome, @IPA_tech.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.