Support

Account

Home Forums Add-ons Gallery Field add thumbnail_id to gallery id db table Reply To: add thumbnail_id to gallery id db table

  • A gallery field stores an array of post ID’s. To add an image you first need to get the value and add the new ID value to it.

    
    $gallery = get_field('gallery', get_the_ID(), false); // get unformatted value
    if (empty($gallery)) {
      $gallery = array();
    }
    $gallery[] = get_post_thumbnail_id(get_the_ID());
    update_field('gallery', $gallery, get_the_ID());