Support

Account

Home Forums General Issues Gallery: Related Images "Uploaded to"… Problem!

Solving

Gallery: Related Images "Uploaded to"… Problem!

  • I’m using WordPress as a straightforward gallery, with all the images accessible via the homepage. Each attachment page features the relevant image, other content and ‘related images’, which link to other images in the gallery. I’m using the ACF Repeater (Image) field (not ACF Gallery field) to ‘attach’ these images in the WordPress back end.

    Related Images: Front and Back End

    It seems to work perfectly, except that every time I save changes made to any image (or rather its fields), the permalink structure of the related images are changed. Whereas before they’d be http://gallery/image-title-1, they then become children of the image they are attached to, i.e. http://gallery/parent-image/image-title-1/. This is due to the WordPress “uploaded to” feature, in cases where you’d want the image ‘post’ to be a child of a parent post.

    It is possible to manually detach them in turn to fix the problem, but I would like to remove this need entirely, since other users will be populating the gallery. I hoped I’d find an easy solution, but I’m not really as advanced with filters etc to know where to start doing it manually. Tried a few plugins that claimed to suppress hierarchies or manipulate attachments but no joy. My permalinks are simply set to “post name”:

    Permalinks

    Is there any way of using the ACF Image field without incurring this behaviour, and if not, how can I automatically remove the hierarchical effect its having on the permalinks?

    Any help hugely appreciated.

    • cduyvis

    • November 19, 2020 at 2:40 am

    I’m running into the same problem; did you ever find a fix for this?

  • I don’t think I ever did find a solution I’m afraid; it’s been a while now since I’ve looked at it, but I think I resolved to reset the permalink manually each time. It works, but it’s hardly a decent fix.

    • cduyvis

    • November 20, 2020 at 9:42 pm

    I asked support for assistance and they suggested: “You can make use of the acf/save_post filter to detach any media from the post.”

    I’m not a programmer so I have no idea where to start with that, but I thought I’d share it in case it’s useful to you.

    I’ll let you know if I ever figure out a solution.

  • 
    add_action('acf/save_post', 'remove_att_from_att

    );
    function remove_att_from_att($post_id) {
    $post_type = get_post_type($post_id);
    if ($post_type != ‘attachment’) {
    return;
    }
    $children = get_children($post_id);
    if (children) {
    // remove filter so this filter does not run again
    remove_filer(‘acf/save_post’, ‘remove_att_from_att`);
    foreach ($children as $child) {
    $child->parent = 0;
    wp_update_post($child);
    }
    // restore filter
    add_action(‘acf/save_post’, ‘remove_att_from_att`);
    }
    }
    `

Viewing 5 posts - 1 through 5 (of 5 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.