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.

Image Field as Post Field is Limiting

  1. David Peralty

    Is there an easy way to get the Image Field that is associated with posts to be just an Upload Field? I want people to upload documents and have them associated with posts.

    Posted 10 years ago on Tuesday November 10, 2009 | Permalink
  2. I don't think there is anyway to do this right now. The field is pretty specific as to how it processes the file that is uploaded, and non-images would have to be processed different than images. We would have to make changes to the plugin and add a file upload (non-images) to the post fields.

    Posted 10 years ago on Thursday November 12, 2009 | Permalink
  3. David Peralty

    Oh, I figured it would have been easy since WP has a "media" upload option on the new post page. I figured images/files would have been handled the same. :$ Is there any way that I can link the file upload to the post then? Maybe pushing the URL through a custom field or something?

    Posted 10 years ago on Thursday November 12, 2009 | Permalink
  4. Dave,
    You could use a hook to create a custom field with the URL of an uploaded file.
    If that works for you, I can send you a code snippet.

    Posted 10 years ago on Friday November 13, 2009 | Permalink
  5. David Peralty

    How would they "know" the URL? I'd love to get this to work so any help you can give would be greatly appreciated. Let me know if you need any details from me.

    Posted 10 years ago on Friday November 13, 2009 | Permalink
  6. You would use the post submission action to edit the post (adding a new custom field) based on the file upload field. At that point, the entry is created and the URL for the file upload is known. I will come up with a code snippet for you.

    Posted 10 years ago on Friday November 13, 2009 | Permalink
  7. Dave,
    The following code will add a custom field to the post that was just created with the URL of a file uploaded from a file upload field. Add it to your template's function.php file.

    add_action("gform_post_submission", "add_post_custom_field");
    function add_post_custom_field($entry){
    add_post_meta($entry["post_id"], "my_custom_field_name", $entry[2]);

    Note that you will have to replace "2" (in $entry[2]) with your file upload field id.
    You can get the id by inspecting the HTML of the file upload field. It's name will be in the following format "input_ID" (i.e. input_2).
    Let me know how it goes.

    Posted 10 years ago on Saturday November 14, 2009 | Permalink
  8. David Peralty

    That worked perfectly. :) Thanks again!

    Posted 10 years ago on Friday November 20, 2009 | Permalink
  9. adew

    If you're using more than one form on your site, bear in mind that the gform_post_submission runs every time a form is submitted. To avoid "empty" custom fields being created by forms that don't require it, modify Alex's code (posted above) to this:

    add_action("gform_post_submission", "add_post_custom_field");<br />
    function add_post_custom_field($entry){<br />
    	if( !empty( $entry[2] ) ) {<br />
    		add_post_meta($entry["post_id"], "my_custom_field_name", $entry[2]);<br />
    	}<br />

    Obviously, change the $entry id with the actual $entry filed id.

    Posted 9 years ago on Monday April 19, 2010 | Permalink

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