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.

Push attachment ID into custom field

  1. daleanthony
    Member

    I'm using Gravity Forms with Advanced Custom Fields by Elliot Condon (If you haven't seen it before, check it out, it's awesome!) which for the most part works amazingly well, there's just one small thing I can't figure out...

    Using the posts fields I've setup a form that catches data and adds a pending review post, all working well, however I was wondering if it is possible to push the attachment ID (for a post image field) into a custom field called 'featuredimage'?

    The reason I'd like to do this is because in wp-admin that is how the ACF plugin catches the image I upload, I'd like the same thing to happen for users who are posting from the front-end using the gravity form I've setup.

    Posted 13 years ago on Wednesday August 24, 2011 | Permalink
  2. Is the featuredimage custom field the same one used by the WordPress featured image functionality? If so then this can be done as a customization. Here is a post that discusses this:

    http://www.gravityhelp.com/forums/topic/fatal-error-when-using-the_post_thumbnail-code-snippet#post-30918

    The good news is Gravity Forms v1.6 adds a new option to the Post Image field to set the image as the featured image for the post that is created. If it's selected then when the Post is created that image is set as the featured image using the WordPress features image functionality automatically.

    Gravity Forms v1.6 will be released as a beta later this week.

    Posted 13 years ago on Wednesday August 24, 2011 | Permalink
  3. daleanthony
    Member

    Thanks for the reply!

    Sadly it isn't the standard WordPress featured image, it's my own custom field I've setup as I don't believe the ACF plugin allows you to set it as a featured image.

    Posted 13 years ago on Wednesday August 24, 2011 | Permalink
  4. You may be able to repurpose the code referenced in that post to accomplish what you want to do. Because it also uses the attachment id.

    Posted 13 years ago on Wednesday August 24, 2011 | Permalink
  5. I'm trying to do the same thing, and failing to get it to work. I've got a custom field generated by Advanced Custom Fields, with a meta_key of 'article-image'.

    I've looked at the code referenced in the link post, and tried pasting a modified version into my functions.php file, but it's not updating my custom field. See code below.

    http://www.pastie.org/3645280

    I've double checked, and the form ID is 4. The images uploaded are attached to the post, so the problem isn't there, it just seems like it's not running the function. (I've tried modifying the last line to update_post_meta($post_id, 'article-image', 'hello'); just to test, and it still didn't update the custom field with 'hello')

    Posted 12 years ago on Thursday March 22, 2012 | Permalink
  6. Strangely, it's just started working. Not sure what did it, as I hadn't touched the function from what I posted before. Perhaps it was clashing with another piece of code in functions.php that I modified in the mean time. Anyway, case closed.

    Posted 12 years ago on Thursday March 22, 2012 | Permalink