PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Post Field = Custom Field, File Upload Displayed on Single.php

  1. I am using WP 3.2.1, and Gravity Forms 1.5.3. No other plugins and currently using Theme "twenty eleven 1.2"
    ===========================
    What I am doing seems to be pretty easy, but I may be missing something.

    I created a GForm using the following POST Fields:
    'Post Title
    Post Body
    Post Excerpt
    Post Category
    Custom Field'

    The "Custom Field" in the Gravity Forms form has been named "File Upload", file type="FileUpload", Custom Field Name="file_attachment"

    When users complete the form, their information is placed in the Post Drafts, including their PDF file, but when I publish this - everything BUT the Custom Field is displayed.

    I went into the "single.php" file of twenty eleven 1.2 and added this piece of code:

    [php]
    <p><?php $customfield = get_post_custom_values("file_attachment");
    if (isset($customField[0])) {
    echo '<h3><a href="'.$customField[0].'" rel="nofollow">Download Now!</a></h3>';
    } ?></p>

    Nothing (in the Custom Fields) displays... What am I missing?

    Posted 12 years ago on Tuesday October 25, 2011 | Permalink
  2. Hi uncgure,

    1 - When you view the post in the admin, can you see that the custom field has a value?
    2 - You might consider retrieving the custom field like this:

    [php]
    <?php echo get_post_meta($post->ID, 'file_attachment', true); ?>
    Posted 12 years ago on Tuesday October 25, 2011 | Permalink
  3. Thanks David! That at least makes it display the custom field value (which is currently just a text-string, but I needed to convert to an URL).

    I did some additional tweaks, but nothing fancy and it seemed to work with this:

    <h3><a href=<?php echo get_post_meta($post->ID, 'file_attachment', true); ?>>Download</a></h3>
    Posted 12 years ago on Thursday October 27, 2011 | Permalink
  4. Hi uncgure,

    Yep, my response was intended to be a starting point. Glad you were able to get this working. :)

    Posted 12 years ago on Thursday October 27, 2011 | Permalink
  5. uncgure, you might want to update your code to make the XHTML valid and prevent problems in the future. You need to quote the URL:

    [php]
    <h3><a href="<?php echo get_post_meta($post->ID, 'file_attachment', true); ?>" title="Download">Download</a></h3>
    Posted 12 years ago on Friday October 28, 2011 | Permalink

This topic has been resolved and has been closed to new replies.