• Hello, WordPress gurus!

    I am trying to save (if it is a new post) or update (if it is an existing post) multiple custom meta-boxes with two different custom fields. I would like to save the post meta as two different keys. So all of the Field A’s (the image) are the value of one key and all of the Field B’s (the description) are the value of another key. All of the Field’s have the same respective id. So all Field A’s have the id field_a and Field B’s have the id field_b.

    I’m trying to wrap my head around how to get this accomplished. Any help would be greatly appreciated. Here’s the code:

    The Meta-Boxes

    function gw_slideshow_meta_fields() {
        global $post;
        echo '<input type="hidden" name="custom_meta_box_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';
        $ImageMeta            = get_post_custom_values('gw_slideshow_image');
        $TextMeta               = get_post_custom_values('gw_slideshow_text');
        $defaultImage         = '#';
        if ($ImageMeta) {
            var_dump($ImageMeta);
            foreach (array_combine($ImageMeta, $TextMeta) as $ImageMeta => $TextMeta){
                $image = wp_get_attachment_image_src($ImageMeta, 'medium');
                $image = $image[0];
                ?>
               <div class="file-input">
                    <div class="alignleft gw_slideshow_image_left">
                    <span class="sort button">|||</span>
                                        <span class="custom_default_image" style="display:none"><?php $defaultImage ?></span>
                                        <input id="gw_slideshow_image" name="gw_slideshow_image" type="hidden" class="custom_upload_image" value="<?php echo $ImageMeta ?>" />
                                        <input class="custom_upload_image_button button" type="button" value="Choose Image" />
                                        <div class="gw_slideshow_image-container">
                                            <img src="<?php echo $image ?> " class="custom_preview_image" alt="" />
                                        </div>
                                        <small class="gw_slideshow_remove-image"> <a href="#" class="custom_clear_image_button">Remove Image</a></small>
                    </div> <!-- end .alignleft -->
                    <div class="alignright gw_slideshow_description-container">
                                        <p class="description">A description of the image.</p>
                                        <textarea type="text" name="gw_slideshow_text" id="gw_slideshow_text"  cols="50" rows="10"><?php echo $TextMeta ?></textarea>
                                        <div class="gw_slideshow_add-more">
                                            <input class="repeatable-remove button" type="button" value="–" />
                                            <input class="repeatable-add button" type="button" value="+ Add More" />
                                        </div>
                        </div><!-- end .alignright -->
                          <div class="clear"></div>
                </div><!-- end .file-input -->
        <?php
            }
        } else {
            ?>
            <div class="file-input">
                    <div class="alignleft gw_slideshow_image_left">
                    <span class="sort button">|||</span>
                                        <span class="custom_default_image" style="display:none"><?php $defaultImage ?></span>
                                        <input id="gw_slideshow_image" name="gw_slideshow_image" type="hidden" class="custom_upload_image" value="" />
                                        <input class="custom_upload_image_button button" type="button" value="Choose Image" />
                                        <div class="gw_slideshow_image-container">
                                            <img src="<?php echo $defaultImage ?>" class="custom_preview_image" alt="" />
                                        </div>
                                        <small class="gw_slideshow_remove-image"> <a href="#" class="custom_clear_image_button">Remove Image</a></small>
                    </div> <!-- end .alignleft -->
                    <div class="alignright gw_slideshow_description-container">
                                        <p class="description">A description of the image.</p>
                                        <textarea type="text" name="gw_slideshow_text" id="gw_slideshow_text"  cols="50" rows="10"></textarea>
                                        <div class="gw_slideshow_add-more">
                                            <input class="repeatable-remove button" type="button" value="–" />
                                            <input class="repeatable-add button" type="button" value="+ Add More" />
                                        </div>
                        </div><!-- end .alignright -->
                          <div class="clear"></div>
                </div><!-- end .file-input -->
                <?php
        }
    
    }

  • The topic ‘Saving and/or Updating Multiple Custom Fields’ is closed to new replies.