Support

Account

Home Forums Add-ons Repeater Field Repeater file field

Solved

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.

  • Sure, but how do I un-mark it? I see no option .

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Repeater file field’ is closed to new replies.