Support » Plugin: CMB2 » Disappearing Images in repeatable group fields

  • Resolved Laura Yeffeth

    (@clampdesign)


    I have a few repeatable groups from with images and it was all working fine until I moved the site from development to the live server. Now some of these images have disappeared from the front end. They still show up on the back end but usually the second or third entry’s image disappears. I tried deleting the entry altogether, saving and re-adding it, but when I added the new entry, it was populated with the first entry data. I removed that and added the correct data and everything shows up except the image.

    I had this happening on several groups but since this was a live site I had to find a new method for the main repeatable group that was causing problems. Now I am left with just once image missing. The code for the repeatable group is:

    $meta_boxes['author_metabox'] = array(
        'id'           => 'author_metabox',
        'title'        => __( 'Author Details', 'cmb2' ),
        'object_types'  => array( 'book', ),
        'fields'       => array(
          array(
            'id'          => $prefix . 'author_repeat_group',
            'type'        => 'group',
            'options'     => array(
              'group_title'   => __( 'Author {#}', 'cmb2' ), // {#} gets replaced by row number
              'add_button'    => __( 'Add Another Author', 'cmb2' ),
              'remove_button' => __( 'Remove Author', 'cmb2' ),
            ),
            'fields'      => array(
               array(
                'name'       => __( 'Author Section Heading', 'cmb2' ),
                'description' => 'For example, About the Author',
                'id'         => 'author_heading',
                'type'       => 'text',
              ),
              array(
                'name'       => __( 'Author Name', 'cmb2' ),
                'id'         => 'author_name',
                'type'       => 'text',
              ),
              array(
                'name' => __( 'Author Portrait', 'cmb2' ),
                'desc' => __( 'Upload an image or enter a URL.', 'cmb2' ),
                'id'   => 'author_portrait',
                'type' => 'file',
              ),
              array(
                'name'    => __( 'Author Bio', 'cmb2' ),
                'id'      => 'author_bio',
                'type'    => 'wysiwyg',
                'options' => array( 'textarea_rows' => 5, ),
              ),
              array(
                'name' => __( 'Heading for Social Media Links', 'cmb2' ),
                'description' => 'For example, Connect with the Author',
                'id'   => 'socialmedia_heading',
                'type' => 'text',
              ),
              array(
                'name' => __( 'Facebook URL', 'cmb2' ),
                'id'   => 'facebook_url',
                'type' => 'text_url',
              ),
              array(
                'name' => __( 'Twitter URL', 'cmb2' ),
                'id'   => 'twitter_url',
                'type' => 'text_url',
              ),
              array(
                'name' => __( 'Google+ URL', 'cmb2' ),
                'id'   => 'googleplus_url',
                'type' => 'text_url',
              ),
              array(
                'name' => __( 'Linkedin URL', 'cmb2' ),
                'id'   => 'linkedin_url',
                'type' => 'text_url',
              ),
              array(
                'name' => __( 'Instagram URL', 'cmb2' ),
                'id'   => 'instagram_url',
                'type' => 'text_url',
              ),
              array(
                'name' => __( 'Pinterest URL', 'cmb2' ),
                'id'   => 'pinterest_url',
                'type' => 'text_url',
              ),
              array(
                'name' => __( 'YouTube URL', 'cmb2' ),
                'id'   => 'youtube_url',
                'type' => 'text_url',
              ),
            ),
          ),
        ),
      );

    And the code to display the fields:

    <?php if ($authors != NULL) : ?>
          <section class="author_content row" id="author">
            <div class="col">
            <?php
            foreach ( (array) $authors as $key => $entry ) :
    
              $author_heading = $author_portrait = $author_bio = $socialmedia_heading = $facebook_url = $twitter_url = $googleplus_url = $linkedin_url = $instagram_url = $pinterest_url = $youtube_url = '';
    
                if ( isset( $entry['author_heading'] ) ) $author_heading = $entry['author_heading'];
                if ( isset( $entry['author_portrait'] ) ) :
                  $author_portrait_id = $entry['author_portrait_id'];
                  $author_portrait = wp_get_attachment_image($author_portrait_id,'medium');
                endif;
    
                if ( isset( $entry['author_bio'] ) ) $author_bio = wpautop($entry['author_bio']);
                if ( isset( $entry['socialmedia_heading'] ) ) $socialmedia_heading = $entry['socialmedia_heading'];
                if ( isset( $entry['facebook_url'] ) ) $facebook_url = $entry['facebook_url'];
                if ( isset( $entry['twitter_url'] ) ) $twitter_url = $entry['twitter_url'];
                if ( isset( $entry['googleplus_url'] ) ) $googleplus_url = $entry['googleplus_url'];
                if ( isset( $entry['linkedin_url'] ) ) $linkedin_url = $entry['linkedin_url'];
                if ( isset( $entry['instagram_url'] ) ) $instagram_url = $entry['instagram_url'];
                if ( isset( $entry['pinterest_url'] ) ) $pinterest_url = $entry['pinterest_url'];
                if ( isset( $entry['youtube_url'] ) ) $youtube_url = $entry['youtube_url'];
    
                $social_media_links = FALSE;
                if ( ($facebook_url != '') OR ($twitter_url != '') OR ($googleplus_url != '') OR ($instagram_url != '') OR ($pinterest_url != '') OR ($linkedin_url != '') OR ($youtube_url != '') ) $social_media_links = TRUE;
              ?>
    
              <h2><?php echo $author_heading; ?></h2>
              <?php if ($author_portrait != '' OR ($social_media_links == TRUE) ) : ?>
              <div class="main_content_image author_image"><?php echo $author_portrait; ?>
                <?php if ( $social_media_links == TRUE ) : ?>
                <div class="socialmedia">
                  <?php if($socialmedia_heading != '') : ?>
                    <h6><?php echo $socialmedia_heading; ?></h6>
                  <?php endif; ?>
                  <?php if ($facebook_url != '') : ?>
                    <a target="_blank" href="<?php echo $facebook_url; ?>"><i class="fa fa-facebook"></i></a>
                  <?php endif; ?>
                  <?php if ($twitter_url != '') : ?>
                    <a target="_blank" href="<?php echo $twitter_url; ?>"><i class="fa fa-twitter"></i></a>
                  <?php endif; ?>
                  <?php if ($googleplus_url != '') : ?>
                    <a target="_blank" href="<?php echo $googleplus_url; ?>"><i class="fa fa-google-plus"></i></a>
                  <?php endif; ?>
                  <?php if ($instagram_url != '') : ?>
                    <a target="_blank" href="<?php echo $instagram_url; ?>"><i class="fa fa-instagram"></i></a>
                  <?php endif; ?>
                  <?php if ($pinterest_url != '') : ?>
                    <a target="_blank" href="<?php echo $pinterest_url; ?>"><i class="fa fa-pinterest"></i></a>
                  <?php endif; ?>
                  <?php if ($linkedin_url != '') : ?>
                    <a target="_blank" href="<?php echo $linkedin_url; ?>"><i class="fa fa-linkedin"></i></a>
                  <?php endif; ?>
                  <?php if ($youtube_url != '') : ?>
                    <a target="_blank" href="<?php echo $youtube_url; ?>"><i class="fa fa-youtube"></i></a>
                  <?php endif; ?>
                </div>
                <?php endif; ?>
              </div>
              <?php endif; ?>
              <div class="entry"><?php echo $author_bio; ?></div>
             <?php endforeach ?>
            </div>
            <a class="back-to-top" href="#top"><i class="fa fa-chevron-circle-up"></i></a>
          </section>
          <?php endif; ?>

    Any help would be appreciated.
    Thank you.

    https://wordpress.org/plugins/cmb2/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Could you provide the dev url, the live url, and an example of the option value that was saved? I have to believe at least part of the issue is file url references

    Thread Starter Laura Yeffeth

    (@clampdesign)

    I was able to get this fixed by uploading a completely new image with a different filename. Selecting the image from media library didn’t work and uploading the same image didn’t work. but changing the filename and re-uploading worked.

    After doing a little more research, I think it could have been an issue with the serialized strings getting messed up with the migration. I tried just correcting the string length in the two places I saw that it was off, but this just removed all the content from the back end, so I had to re-enter everything. Even deleting the string from the database and saving and then saving the post, when I re-entered the exact same image, it didn’t show.

    I don’t know if it’s helpful at all for you now, but the dev URL is:
    <a href=”http://www.clampdesign.com/dev/bbv/book/better-than-vegan/
    “>http://www.clampdesign.com/dev/bbv/book/better-than-vegan/

    which still shows the second author image in the back end but doesn’t show up on the front end.

    and the live URL is:
    http://www.benbellavegan.com/book/better-than-vegan/
    which has the new image showing up.

    The database entry for the _cmb2_author_repeat_group meta_key is

    a:2:{i:0;a:13:{s:14:"author_heading";s:17:"About the Authors";s:11:"author_name";s:15:"Chef Del Sroufe";s:18:"author_portrait_id";s:3:"268";s:15:"author_portrait";s:86:"http://www.clampdesign.com/dev/bbv/wordpress/wp-content/uploads/2014/12/Del-Sroufe.jpg";s:10:"author_bio";s:834:"<div class="entry">
    
    <b>Del Sroufe</b>'s passion for cooking began at eight years old and never faded. Sroufe opened Del’s Bread, a vegan bakery, before beginning vegan meal delivery service in 2001, serving eclectic plant-based cuisine to Columbus residents. In 2006, Sroufe joined Wellness Forum Foods as co-owner and chef. Sroufe also joined The Wellness Forum as a member where, after a lifetime of yo-yo dieting, he has lost over 200 pounds on a low fat, plant-based diet. He continues to teach cooking classes at local venues like Whole Foods, Community Recreation Centers, and The Wellness Forum. Sroufe is also the author of <i>Better Than Vegan</i> and the bestseller, <i>Forks Over Knives—The Cookbook</i>.
    
    Learn more at <a href="http://wellnessforumfoods.com/" target="_blank">wellnessforumfoods.com</a>.
    
    </div>";s:19:"socialmedia_heading";s:16:"Connect with Del";s:12:"facebook_url";s:19:"http://facebook.com";s:11:"twitter_url";s:18:"http://twitter.com";s:14:"googleplus_url";b:0;s:12:"linkedin_url";b:0;s:13:"instagram_url";b:0;s:13:"pinterest_url";b:0;s:11:"youtube_url";b:0;}i:1;a:6:{s:11:"author_name";s:11:"Glen Merzer";s:15:"author_portrait";s:102:"http://www.clampdesign.com/dev/bbv/wordpress/wp-content/uploads/2014/12/Glen-Merzer-e1419962515988.jpg";s:10:"author_bio";s:487:"<strong>Glen Merzer</strong> is coauthor with Del Sroufe of <em>Better Than Vegan</em>, with Pamela A. Popper, PhD, ND of <em>Food Over Medicine</em>, with Howard Lyman of <em>Mad Cowboy</em>, with Howard Lyman and Joanna Samorow-Merzer of <em>No More Bull!</em>, and with Chef AJ of <em>Unprocessed</em>. Merzer is also a playwright and screenwriter, having most recently completed a screenplay for<em> Mad Cowboy</em>. He has been a vegetarian for 40 years and a vegan for the last 20.";s:19:"socialmedia_heading";s:17:"Connect with Glen";s:12:"facebook_url";s:49:"https://www.facebook.com/GlenMerzerAuthor?fref=ts";s:11:"twitter_url";s:30:"https://twitter.com/glenmerzer";}}

    I said originally that this issue started when I moved from the dev server to the live server, but that isn’t quite right. I have a local server as well, so I think the issues started when I migrated from my local server to my dev server and obviously I can’t share my local server.

    At the moment everything is working for me although I imagine whatever caused this error could show up when trying to edit or add entries to the repeatable fields in the future. If you think there is an issue and I can give you any more information to help you troubleshoot, just let me know. I really appreciate your work on this plugin which I plan to continue to use on new sites going forward so if I can help in any way, I’d be happy to.

    Thanks again for always responding so quickly.

    Wow. I just had this exact same problem. I came here to see if anyone had any ideas.

    I just moved my site from test-site.dev on my laptop’s local apache setup to test-site.dev on my desktop’s local apache setup. The databases (including post IDs) are identical (besides the db name), but for some reason, the repeatable group entries that I have are not showing up. I can see them in the database (like @clampdesign), but I really don’t want to have to re-enter all of these fields. I have 15-20 Title/Description pairs attached to one page.

    I don’t have a live version of the site yet, so I won’t be able to show you what I’m talking about, but these entries are not showing up on the front-end or the page edit screen. The custom fields DO show up (as empty fields), just not the filled-out entries that should be there. Any ideas how to get WP to recognize them?

    Should I create a new thread?

    Thanks in advance for any help.

    EDIT: Two notes.
    1) In the process of moving the database. I’m fairly certain this has nothing to do with this problem, but just throwing it out there.
    2) My version of the issue has nothing to do with file URLs, but seems to be the exact same problem as @clampdesign’s.

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Yeah, serialized data is tricky with migrations, if things don’t match when moving, they tend to be dropped completely.

    For some clarification/example:

    a:2:{i:0;a:13:{s:14:

    The A stands for “array”, and the 2 stands for how many indexes it has. So your option had an array with 2 indexes.

    The I stands for “index” and 0 is which index. So for that part, we’re looking at index 0, and it holds its own array that has 13 indexes.

    Since the nested array goes right into S which is for “string”, it’s likely a named array. The 14 indicates how many characters are in the string at that spot. “author_heading” is the index name, it has 14 characters. And so on. There’d be potentially examples of Objects in there as well, or from other stored options. Much the same.

    If you’re changing from a url of “http://foo.com&#8221; to “http://foofoofoo.com&#8221;, then the string character counts need to be updated to match, or else they’ll be lost. In this example, from 14 characters to 20. Same things need to occur if you’re removing indexes in arrays and whatnot, the index count would need updated.

    Thankfully get_option/update_option handle these for you, but if you’re doing direct queries, you don’t get that luxury.

    Always a “fun” thing to debug and work with. Hopefully that makes sense.

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    360zen you replied while I was typing up my answer.

    When dealing with migrations, it’s going to be advantageous to find scripts or plugins that specifically state that they handle data serialization. Otherwise you may end up having to do some editing by hand, or re-setting spots, both which can be tedious.

    Hmm… I think I understand your explanation about why this is tricky. However, I don’t see how it applies to my situation. The two instances of the site don’t seem to be meaningfully different.

    What would I be looking for if I were to attempt a manual fix here? Do you know of any migration scripts that would do this better?

    EDIT: Scratch all of that. The entry appeared to be the same, but after scrolling deeper, I think a big chunk is missing. …and it’s fixed! Thanks for the info!

    Thread Starter Laura Yeffeth

    (@clampdesign)

    For anyone else who might come upon this thread. I am now using WP Migrate DB Pro to do my migrations. It handles the serialization strings for you and saves a ton of time. I just wish I discovered it earlier. I think I’ll make back the cost of the plugin in time saved pretty quickly.

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    WP Migrate DB Pro is magical.

    Glad things are sorting themselves out you two.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Disappearing Images in repeatable group fields’ is closed to new replies.