Support

Account

Home Forums Add-ons Gallery Field Idiot Proof an ACF Gallery

Solving

Idiot Proof an ACF Gallery

  • Hi

    I have a website where users upload photos into an ACF Gallery field. The problem is the users often mess up and do not click the “Select” button. They successfully upload their photos, but they do not select and insert them into the gallery.

    I have tried everything including tutorials (no one reads them). Big red font everywhere yelling at them to click the select button. Still many of them do not.

    I was thinking maybe I could automatically when uploaded trigger the photos to be added to the gallery whether or not the user clicks the “Select” button. Has anyone tried this or does anyone have an idea of how to best attack this problem to idiot proof my gallery field and force all uploaded photos to be automatically inserted in the gallery.

    The users then if they mess up could always delete photos from the gallery (or I as webmaster could do so). But by default anything they upload will be automatically inserted with the need to hit the select button.

  • For example is the best way to do this something like hooking into add_attachment and then modify the gallery field?

  • I may have solved this with the below if anyone else ever runs into this issue. It is limited to affecting uploads only to a certain post type. Not sure if you could limit to only uploads via the gallery field somehow…

    function add_filter_upload_image($attach_id){
    $post_id = wp_get_post_parent_id( $attach_id );
    $post = get_post($post_id);
    if($post->post_type == <custom-post-type>){
    $array = get_field(‘field_5f0dcbfc35af4’, $post_id, false);
    if (!is_array($array)) {
    $array = array();
    }
    $array[] = $attach_id;
    update_field(‘field_5f0dcbfc35af4’, $array, $post_id );
    }
    }
    add_filter(‘add_attachment’, ‘add_filter_upload_image’, 10, 1);

  • One issue is that once the user exits the images do not show up in the gallery area which may cause confusion.

    I was thinking I could force a save and page refresh…but not sure how to trigger that event.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.