Forums

[resolved] Custom Field Plugin Get File URL (5 posts)

  1. youngonline
    Member
    Posted 1 year ago #

    So I'm using the custom field template plugin. I have numerous file fields defined in the template. When making a post I choose the files to upload and they do so.

    What i need to know is how i get the urls of the files that i uploaded into that specific post. They show up in the media library but it states they are not attached to any post, so i cant use the get_attachment_url method.

    I need it to display the url as one would type it, so http://www.example.com/blahblah.jpg

    Thanks in advance.

  2. youngonline
    Member
    Posted 1 year ago #

    Sorted.

  3. Dave
    Member
    Posted 1 year ago #

    youngonline,

    Care to share how you solved this issue? I'm experiencing the same challenge. I've uploaded a PDF, but when I try to display it on a page, all I get is a number (most likely an ID of some kind). But I can't figure out how to get the URL.

    THanks,
    Dave

  4. youngonline
    Member
    Posted 1 year ago #

    <?php $variable_name = get_post_meta($post->ID, 'Custom_Field_Name', true); ?>
    
    <?php if ($variable_name): ?>
    <?php echo wp_get_attachment_url($variable_name); ?>
    <?php endif; ?>

    Just replace variable_name with whatever you wish to call it and Custom_Field_Name with whatever you named the field in the plugin.

  5. Dave
    Member
    Posted 1 year ago #

    Just what I was looking for, young. Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic