Support

Account

Home Forums Backend Issues (wp-admin) gravity forms post creation + afc Reply To: gravity forms post creation + afc

  • There are a few ways to do this. Here’s one way with the Gravity Advanced Post Creation Add-On that is included with the Gravity Elite License.

    1. Use the APC media merge tag as explained in the video for Matching up Images with Advanced Custom Fields (ACF) or other Custom Fields using the Advanced Post Creation Add-On

    For example, while editing a Post Creation feed and choosing a value for a custom field name under, select “Add Custom Value” at the bottom of the select menu and then enter

    {apc_media:IMAGE_FIELD_ID:ids}

    This will assign an attachment post ID to the meta field related to your ACF field. It will not run update_field.

    2. Use the hook gform_advancedpostcreation_post_after_creation_YOURFORMID to run update_field once a post is created:

    add_action('gform_advancedpostcreation_post_after_creation_YOURFORMID', 'my_gf_new_organization', 10, 4);
    function my_gf_new_organization($post_id, $feed, $entry, $form) {
       $logo = get_field('field_LOGO_FIELD_KEY',$post_id);
       if ( $logo && is_numeric($logo) ) { //sanity check
          $logo_id = $logo;
          $update_result = update_field('field_LOGO_FIELD_KEY',$logo_id,$post_id);
       }
    }

    If you do not use the filter, you can alternatively get attachments for the post and look for the one you want that matches entry data. Or you can just get the first attachment if there is only one. Then, use update_field to add it to the post.

    Finally, if you do not need to update_field on post creation or you do not want to, and you do not want to use the gform_advancedpostcreation_post_after_creation at all, you can check to see if get_field returns a numeric value and run update_field before display. If you don’t want to update_field at all, you can also consider using acf_get_attachment (which is fairly undocumented) with the attachment id.