Using the Gravity Forms + Custom Post Types WordPress plugin to map your Gravity-Forms-generated posts to a custom post type is very handy, but I noticed that it doesn’t seem to work with file uploads. This is because by default, Gravity Forms saves files to /wp-content/uploads/gravity_forms and stores their URLs. ACF on the other hand, saves files to the WP Media Library and stores their attachment IDs. The class below can be used to solve problem this by doing the following:

  • After the form has been submitted, get the file from the GF uploads directory and insert it into the WordPress Media Library.
  • Update the post to save the attachment ID in the ACF form field, so ACF knows where to look for it.
  • Delete the original file that was uploaded to the GF uploads directory.

Be sure to change line 53 to reflect the ID of your Gravity Form, and lines 62 & 63 to reflect the Gravity Forms an ACF field IDs that you want to map to one another.

7 comments

  1. Fabio infante December 16, 2016 at 8:43 pm

    Reply

    Hi kellen, thanks for share, I want to upload multiple files for several custom fields at the same time on the same form

  2. Tiffany Israel April 4, 2017 at 11:07 am

    Reply

    Is there a way to get this to work with out a post submission? Also for line 48 is this just the title of the Gravity forms, no special “nicename” or anything?

  3. Aaron June 21, 2017 at 6:15 pm

    Reply

    Thanks for posting this. I have been unable to get it to work. Is it simply including the file into functions.php and updating the three variables in the file?

    Thanks!

    • Kellen Mace July 17, 2017 at 7:05 am

      Reply

      Hey Aaron – as this was originally, written, you’d have to include the code in your project, then instantiate the class using new WDSP_Event_Form();. I’ve updated it so that it gets instantiated on the last line though, so you don’t have to worry about that anymore. Although it would be possible to paste it all into functions.php, I would recommend creating a new plugin with a header at the top (an example of one is here: https://developer.wordpress.org/plugins/the-basics/header-requirements/), then pasting all the code from this post into it, changing the new lines I mention in the post. Then you would be able to save that plugin to your web server, activate the plugin and be all set. Best of luck!

  4. Guy Lev July 11, 2017 at 12:28 pm

    Reply

    Hi kellen.
    For some reason this doesn’t work for me 🙁
    I cannot see the image in the media library and it doesn’t show in the gallery 🙁
    Can you help somehow?

    Thanks!!!!!!!
    Guy

    This is my function.php

    https://gist.github.com/oneguy9/aa86e6d54de1e6430efa4b64ed84b101

    • Kellen Mace July 17, 2017 at 7:45 am

      Reply

      Hey Guy – as this was originally, written, you’d have to include the code in your project, then instantiate the class using new WDSP_Event_Form();. I’ve updated it so that it gets instantiated on the last line though, so you don’t have to worry about that anymore. Although it would be possible to paste it all into functions.php, I would recommend creating a new plugin with a header at the top (an example of one is here: https://developer.wordpress.org/plugins/the-basics/header-requirements/), then pasting all the code from this post into it and changing the new lines I mention in the post. Then you would be able to save that plugin to your web server, activate the plugin and be all set. Best of luck!

Leave a reply

Your email address will not be published. Required fields are marked *