Home › Forums › General Issues › Outputting info from a 'File' field? › Reply To: Outputting info from a 'File' field?
This code below seems to work:
<?php
$file = get_field('product_brochure_pdf');
if( $file ):
// vars
$url = $file['url'];
$title = $file['title'];
endif; ?>
<?php if(get_field('product_brochure') == 'yes') : ?>
<a href="<?php echo $url; ?>" title="<?php echo $title; ?>" target="_blank"><?php echo $title; ?></a>
<?php else : ?>
<?php endif; ?>
Can any of you guys who are more versed in PHP check that out and see if there are any glaring issues? Like I said, it does work, just want to make sure it’s coded correctly.
What it should be doing is if someone chooses ‘Yes’ from the radio button choice (meaning yes, there is a product brochure) it will then show the conditional ‘File’ field called Product Brochure PDF (to allow someone to upload a PDF). The code will output the link to the PDF along with the title of the PDF.
If someone selects ‘NO’ on the radio button choice, it simply won’t display anything on the front end.
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.