Support

Account

Home Forums ACF PRO Gallery field preformance issue

Solved

Gallery field preformance issue

  • Hello,
    I’ve noticed very weird thing – my client put 105 images in gallery field. I’ve tried to get them using ‘get_field’ function. It works but it takes about 4-5 second on client’s server. I’m talking only about execution time of get_field function.

    So, here are results from my localhost, gallery field with 105 images:
    1) get_field – 1.0430738925934s
    2) get_post_meta – 0.00030398368835449s

    and last one:

    $field = get_post_meta(31, 'companyImages');
     $output = array();
     for($i=0; $i<count($field[0]);$i++) {
         $output[] = wp_get_attachment_image_src($field[0][$i], 'medium');
     }

    time: 0.12242698669434s

    Could anyone explain the diffrence beetwen this times?

  • Hi @mrshemek

    When getting the gallery field’s value, ACF will format it. This means it will load all the image data for each image – resulting in the longer load time.

    You should make use of the 3rd parameter for the get_field function which disables the formatting of a value:
    get_field('companyImages', false, false);

    This will load only the DB value without formatting and will return an array of attachment IDs

    Cheers
    E

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

You must be logged in to reply to this topic.