Support

Account

Forum Replies Created

  • 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.

  • John Huebner, this is useful, but I noticed a problem that some people may have if they don’t read your code and paste it into their functions file. I didn’t have this problem myself, but I imagine others might…

    People: Please note that this function deletes field data by name. This can get you in trouble if you are not careful. If you have two custom post types, for example:

    – project
    – staff member

    And they both have a field with the same name but for different purposes, say “subtitle,” deleting a field from one field group will delete ALL data for all fields with that name. In this example, if you delete “subtitle” from staff member, than all project “subtitles” will be deleted.

    Hope this helps someone…

  • Same issue. Fixed by noticing that when switching domains in wpengine, the wordpress settings domain didn’t change, which is used by ACF to make the ajax request.

Viewing 4 posts - 1 through 4 (of 4 total)