Get file url in template

Support General Get file url in templateResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #46013
    AndrewAndrew
    Participant

    Hi there, I have a file field called fees_file_upload. I'm trying to provide the file as a download in my page (using Oxygen) but the codse samples given just give me an error. I'm trying to use this snippet:

    <?php $files = rwmb_meta( 'fees_file_upload' ); ?>
    <h3>Uploaded files</h3>
    <ul>
        <?php foreach ( $files as $file ) : ?>
            <li><a>"><?= $file['name']; ?></a></li>
        <?php endforeach ?>
    </ul>
    

    But I get the following error:
    Warning: foreach() argument must be of type array|object, string given in /home/customer/www/duod37.sg-host.com/public_html/wp-content/plugins/oxygen/component-framework/components/classes/code-block.class.php(133) : eval()'d code on line 4

    How can I get the URL of the file to use in my page?

    #46014
    AndrewAndrew
    Participant

    Sorry this is the code snippet:

    <?php $files = rwmb_meta( 'fees_file_upload' ); ?>
    <h3>Uploaded files</h3>
    <ul>
        <?php foreach ( $files as $file ) : ?>
            <li><a href="<?= $file['url']; ?>"><?= $file['name']; ?></a></li>
        <?php endforeach ?>
    </ul>
    #46024
    PeterPeter
    Moderator

    Hello Andrew,

    Please try to add the specific post ID to the helper function rwmb_meta() and check if it works:

    <?php $files = rwmb_meta( 'fees_file_upload', '', 123 ); ?>

    where 123 is the post ID. Following the documentation https://docs.metabox.io/functions/rwmb-meta/

    #46069
    AndrewAndrew
    Participant

    Hi Peter,

    Thank you for that, it worked perfectly.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.