Skip Navigation

[Resolved] Images gallery missing

This thread is resolved. Here is a description of the problem and solution.

Problem:

The customer duplicated a site, and on the new version (SilverCoast), property images were missing. The image src attributes pointed to placeholders (data:image/gif;base64...) instead of actual image URLs. The backend displayed images correctly, but they did not show up on the frontend.

Solution:

We identified that the issue was related to custom code responsible for fetching media IDs using full media URLs. The original code checked the database for the full URL, including the domain, which failed after site duplication. We modified the code to extract the filename and match it in the database, ignoring the domain format. This allowed the media ID retrieval to work correctly across sites.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 2 replies, has 2 voices.

Last updated by kristofG 1 month, 2 weeks ago.

Assisted by: Mateus Getulio.

Author
Posts
#2780391

I have duplicated the site hidden link to hidden link
On the SilverCoast website, the images for the property are missing, please compare
hidden link with
hidden link

Instead of jpg images, the src has been changed to <img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-orig-src="" width="" height="" alt="" title="" aria-label="" class="img-responsive wp-image- lazyloaded">

#2780431

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

If you try to edit that post(Villa te Huur in Santa Catarina) in the back end, do you see the media in there in the migrated site? If you compare it to the original site, do you spot any differences in the post edit screen?

What if you try to edit the view and update the gallery in the migrated site, checking if the custom field is properly set up in there and making the needed adjustments?

Does that fix the issue?

Thank you, please let us know.
Mateus

#2780447
Screenshot_4.jpg

- The backend looks just fine, all property images are visible.
- I have switched position of the last 2 images to trigger some kind of update, but the problem still persists.
- I have edited the View to limit to 10 images, but the problem still persists.

#2780467

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi,

To suggest the best way to fix this, I'll need to see how this view is set up in the admin area.

Can you please share temporary admin login details?

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Mateus

#2781726

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

Thank you for sharing that information.

I checked it that if I delete one of the images of the gallery in the post edit screen and upload the same image again it starts showing up:

hidden link

So the issue is probably not coming from the template but something with the images.

I'd like to ask permission to make a copy/staging version of your site where I can debug this closely without affecting the live site. I'll make sure to delete this copy as soon as we get this issue fixed.

I need to switch themes, disable plugins etc. I'm afraid of debugging directly on the live site and cause issues to your visitors. Also, it is important to test a different setup as part of the troubleshooting.

If you already have a staging or could create one, it is even better, I enabled the private fields for your next reply in case you have it, if not I can create it.

Thank you, please let us know.
Mateus

#2781798

Hi, I don't have a staging at the moment, but feel free to duplicate the site as per your needs.

#2782326

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello Kristof,

Upon further review, I noticed that the issue steamed from this custom code responsible for calling the avada gallery shortcode passing the IDs inside the theme's function file:

add_shortcode('repeating-images-gallery', 'repeating_images_gallery_func');
function repeating_images_gallery_func($atts, $content) {
    global $post, $wpdb;
      
    $images = get_post_meta($post->ID, 'wpcf-image-gallery', false);
    $ids = array();
    foreach ($images as $image) {
        $attachment_id = $wpdb->get_var($wpdb->prepare(
            "SELECT ID FROM $wpdb->posts WHERE guid = %s",
        $image
        ));
        $ids[] = $attachment_id;
    }
    $out = do_shortcode('[fusion_gallery image_ids="' . implode(",", $ids) . '" layout="grid" columns="4" column_spacing="20" lightbox="yes"][/fusion_gallery]');
    return $out;
}

I changed the code slightly, excluding the domain format of the media URL checking, https/http, www/non-www. So now instead of checking for something like this in the DB:

hidden link

It'll go looking for this and retrieve the media ID correctly:

/wp-content/uploads/2024/04/image00033.jpeg

Please check the final code:


add_shortcode('repeating-images-gallery', 'repeating_images_gallery_func');
function repeating_images_gallery_func($atts, $content) {
    global $post, $wpdb;
      
    $images = get_post_meta($post->ID, 'wpcf-image-gallery', false);
    $ids = array();    

    foreach ($images as $image) {
        // Extract the filename from the full URL
        $file_name = basename($image);        
        
        // Search for the attachment by filename, ignoring the domain
        $attachment_id = $wpdb->get_var($wpdb->prepare(
            "SELECT ID FROM $wpdb->posts WHERE guid LIKE %s",
            '%' . $file_name
        ));

        // Only add non-null IDs to the array
        if ($attachment_id) {
            $ids[] = $attachment_id;            
        } else {            
        }
    }
    
    // Generate the gallery shortcode output
    $out = do_shortcode('[fusion_gallery image_ids="' . implode(",", $ids) . '" layout="grid" columns="4" column_spacing="20" lightbox="yes"][/fusion_gallery]');
    return $out;
}

I tested it and it seems to be working now, can you please review it?

Thank you,
Mateus
#2782351

Wow, that is some clever thinking!!
Should I also change that code on the original website, 2ndplaceinportugal.com or leave it like that there?

#2782464

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Applying the updated code to the original website (2ndplaceinportugal.com) is recommended for consistency and to prevent potential future issues. However, if the original site hasn't experienced similar problems and you prefer not to modify it, leaving it unchanged is also fine. The choice is yours, but updating both sites ensures they function consistently.

If you decide to update, I'd recommend making a backup fist, just in case.

Best regards,
Mateus

#2782603

thank you!