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.
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.
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.
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?
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.
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.
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.
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.
That worked perfectly. :) Thanks again!
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.