Home Forums Add-ons Gallery Field Populate post images in new gallery add-on


Populate post images in new gallery add-on

  • Hi Eliot,
    I have an existing site that has a lot of articles with images already attached to them and I have recently purchased and installed the gallery addon. It works great for all new posts bu the images don’t show on the old posts.

    How do i get the images to show on the old posts? They dont appear in the gallery form on the post page.

  • Do you mean they don’t appear automatically in the old posts or you can’t see them if you go to add images to the gallery field?

    I don’t think there is any easy way for you to accomplish what you want other than editing each old post and adding the correct images to the gallery field so that the data gets saved into the database and you can display it in your theme. This can possibly made easier if you set the gallery field to show only images uploaded to the post.

    Of course there could be a way to write a php script that would fetch the old images from old posts and alter the post custom metadata in the database to contain the gallery field code…

    I don’t know exactly how you have your previous content set up but one another option could be to code your theme files in such way that if there is a new gallery field with content, display it but if not then use the old way and use php to alter how that data is handled…

  • Yes thats exactly what I’ve done. I had an existing carousel that pulled images that were attached to the post. But once I implemented ACF gallery…my images stopped appearing in some posts, so I have the new script and the old script running together and I just check to see if the gallery field has images stored. I m also running WPML, that’s why i check for language..

    // get the acf var depending on language using WPML
    $images = get_field( ( ICL_LANGUAGE_CODE==’fr’ ? ‘gallerie’ : ‘gallery’ ) );
    $src_str = ‘get_field’;
    $num_imgs = count($images);

    // Do we have images in the ACF Gallery ?
    if($num_imgs > 0 && is_array($images) ) {
    } // no images in ACF gallery but we do have images attached to post
    $images = get_children( ‘post_type=attachment&post_mime_type=image&output=ARRAY_A&orderby=menu_order&order=ASC&post_parent=’.$post->ID);
    $src_str = ‘get_children’;

    //if we have images enqueue the carousel scripts
    if( $images ):
    // Galleria Files


    ‘MyAjax’, array(” => ”,)


    <!– Display HTML –>
    <div id=”galleria”>
    <?php foreach( $images as $image ): ?>
    guid ); ?>” alt=”<?php echo ( $src_str == ‘get_field’ ? $image[‘alt’] : $image->post_title ); ?>” />
    <?php endforeach; ?>


    <?php endif; ?>

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

The topic ‘Populate post images in new gallery add-on’ is closed to new replies.