Garet H. Garet H. - 6 months ago 34
PHP Question

WordPress using Fullscreen Galleria to display ImPress Listings images

I am using IMPress listings to display manually display Real Estate Listings. For the single listings there is a wysiwyg for adding images for the image gallery one at a time.

enter image description here

These output using

<?php echo do_shortcode(get_post_meta( $post->ID, '_listing_gallery', true)); ?>

I would like to use Fullscreen Galleria to display the images. I here is what I tried. This doesn't work because the shortcode requires image ids.

echo do_shortcode('[fsg_link class="btn-primary" include="' . get_post_meta( $post->ID, '_listing_gallery', true) . '"]View Full Screen[/fsg_link]');

It appears that this particular short code requires image id's and not HTML.

What would be the best way to display image ids so it outputs like so

echo do_shortcode('[fsg_link class="btn-primary" include="501,502,503"]View Full Screen[/fsg_link]');


Answer Source


function pippin_get_image_id($image_url) {
        global $wpdb;
       $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url )); 
return $attachment[0]; 

Page Template

    if (get_post_meta( $post->ID, '_listing_gallery', true) != '') { 

        $image_url = get_post_meta( $post->ID, '_listing_gallery', true);
        $doc = new DOMDocument;
        $galleryimg = $doc->getElementsByTagName('img');

        $images = array();

        foreach ($galleryimg as $galleryimg){

            $galleryimg = $galleryimg->getAttribute('src');             
            $image_id = pippin_get_image_id($galleryimg);
            array_push($images, $image_id);                 
            $string = rtrim(implode(',', $images), ',');


    echo do_shortcode('[fsg_link class="btn-primary" include="' . $string . '"]View Full Screen[/fsg_link]');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download