Support

Account

Home Forums Search Search Results for 'acf_get_attachment'

Search Results for 'acf_get_attachment'

reply

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

  • 
    $image = acf_get_attachment($post_id);
    
  • It’s as if the plugin is causing ACF to behave as if you have the field set to return the image ID rather than an image array.

    Well, I can help you with a hack, but not finding the cause of or fixing the incompatibility. I’m afraid that fixing it will take several hours of debugging.

    Here is a hack to try, no guarantee it will work though

    
    $image = get_field('logo', 'option');
    if (!is_array($image)) {
      $image = acf_get_attachment($image);
    }
    $url = $image['url'];
    

    To get this fixed properly, you should probably contact the plugin author for the filter plugin. You might get a run-a-round unless you can point to a bug in their code though.

    You can also thy submitting a new ticket here http://support.advancedcustomfields.com/new-ticket/. The ACF support staff may be able to help you, but that I can’t say. I only help out here of the forum.

Viewing 3 results - 1 through 3 (of 3 total)