Home › Forums › Add-ons › Repeater Field › Repeater file field
Hi,
Can anyone help me out? I have a repeater file field. I want to display the file title instead of the url. How do I do this?
$rows = get_field('horse_official_documents');
if($rows)
{
foreach($rows as $row)
{
echo '<div><a href="'. $row['horse_official_document'] .'" target="_blank">' . $row['horse_official_document'] . '</a></div>';
}
}
Thank you!
I suppose you are using a File field. In that case you can specify that the field returns an array (see the screenshots in the documentation). Then you should be able to call the title using $file['horse_official_document']['filename']
.
Hi Daniel,
Thanks for your reply. Yes I’m using a File field (subfield) in my Repeater field.
When I add [‘filename’] it returns ‘h’ as file name?
$rows = get_field('horse_official_documents');
if($rows)
{
foreach($rows as $row)
{
echo '<div><a href="'. $row['horse_official_document'] .'" target="_blank">' . $row['horse_official_document']['filename'] . '</a></div>';
}
}
I want the output to be:
<a href="https://www.breeders.site/wp-content/uploads/2020/01/score-mares-01.jpg">score-mares-01.jpg</a>
What am I missing?
Have you actually checked if the field is configured to return an array?
Please dump the contents of the field via var_dump( $row )
and show me what it spits out.
Thanks for pointing me in the right direction. I have been switching settings before posting this topic. The field was actually configured to output url and not an array.
Your solution $file['horse_official_document']['filename']
works fine now. Thanks so much!!!
Glad I could help. Though, would you please un-mark your post as “topic solution” and mark mine instead, please? I need it for my e-genitals.
The topic ‘Repeater file field’ 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.