Support

Account

Home Forums Feature Requests Speed up work with new option in gallery field Reply To: Speed up work with new option in gallery field

  • 
    add_filter('acf/load_value/name=gallery_field_name', 'bob4bob_load_gallery_from_post', 10, 3);
    function bob4bob_load_gallery_from_post($value, $post_id, $field) {
      if (!value !== NULL) {
        // field has a value, don't change it
        return $value;
      }
      $images = get_attached_media('image', $post_id);
      if (count($images)) {
        $value = array();
        foreach ($images as $image) {
          $value[] = $image->ID;
        }
      }
      return $value;
    }