Home › Forums › Add-ons › Repeater Field › PDF Attachment as Link
Hello,
i have a little question. I have a table with to Repeaterfields like:
| job | location | <- Static Table
| Developer | Germany | <- Two Fields
Now i want to link the job (here developer) with an attachment (job pdf).
The only Option i found, was a new Repeaterfield with Attachment, but these will seperate displayed after the location. I just want to have 2 things in the table with job is linked with an pdf.
Thank you π
Hi @hartu
Could you please tell me where did you want it to show up?
If it’s on the front end, I believe you can add a new file custom field to the repeater and then add the link to the job text like this:
<?php
// check if the repeater field has rows of data
if( have_rows('repeater_field_name') ):
// loop through the rows of data
while ( have_rows('repeater_field_name') ) : the_row();
// display a sub field value
$file = get_sub_field('file_sub_field');
if( $file ):
?>
<a href="<?php echo $file['url']; ?>"><?php the_sub_field('job_sub_field'); ?></a>
<?php endif;
endwhile;
else :
// no rows found
endif;
?>
I’m afraid you can’t do it on the backend, though. I’m sorry for the inconvenience.
I hope this helps π
Hello James :-)!
Right it should be show on the Frontend. So i wanna try your Code.
Thats my code at the moment:
(I added your Code as a example)
// Wenn mindestens 1 Datensatz vorhanden ist
if( have_rows('stellen_ds_en' , 1779) ) {
echo '<table width="100%">';
while( have_rows('stellen_ds_en' , 1779)) : the_row();
// Bezeichnung aus Feld laden
$bezeichnung = get_sub_field('bezeichnung');
// Ort aus Feld laden
$ort = get_sub_field('ort');
//Here goes your Code?
if ( $file ):
?>
<a href="<?php echo $file['url']; ?>"><?php the_sub_field('bezeichnung'); ?></a>
// Anhang Text aus Feld laden
echo "<tr><td width='50%'>$bezeichnung</td><td width='50%'>$ort</td></tr>";
// 3 Felder ausgeben
endwhile;
echo '</table>';
}
?>
Hi @hartu
I’m not sure which one is the file custom field, so forgive me if I’m wrong (please keep in mind that you need to create a new file custom field in your repeater field). If the file custom field is ‘ort’, you need to do it like this:
// Ort aus Feld laden
$ort = get_sub_field('ort');
//Here goes your Code?
if ( $ort ):
?>
<a href="<?php echo $ort['url']; ?>"><?php the_sub_field('bezeichnung'); ?></a>
<? endif;
Also, you need to set the return value of your file custom field to “File Array”. I’ve attached a screenshot for your reference.
Hope this helps π
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!
Weβre hard at work on ACF 6.1, and Beta 1 is now available π
— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Letβs take a look π§΅https://t.co/Y0WcAT11l4
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.