Support

Account

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.