meta-box icon indicating copy to clipboard operation
meta-box copied to clipboard

image_advanced field inside group disappears on save

Open sebgrey opened this issue 9 years ago • 5 comments

Hi, I am running Wordpress 4.5.3, Meta Box 4.8.7 and Meta Box Group extension 1.1.3. Recently I have experienced issues with using image_advanced field types inside groups: if another field inside the group is edited and the page is saved, the value of the image field disappears. The meta value row is deleted altogether from the database. I would hugely appreciate advice and/or a fix.

sebgrey avatar Jul 12 '16 18:07 sebgrey

I think i'm having the same problem. This seems to fix it:

diff --git a/meta-box-group/class-rwmb-group-field.php b/meta-box-group/class-rwmb-group-field.php
index 2999e5f..c2f018b 100644
--- a/meta-box-group/class-rwmb-group-field.php
+++ b/meta-box-group/class-rwmb-group-field.php
@@ -122,7 +122,11 @@ class RWMB_Group_Field extends RWMB_Field {
                 * @see RWMB_Field::meta()
                 */
                if ( $child_field['clone'] || $child_field['multiple'] ) {
-                       if ( empty( $meta ) || ! is_array( $meta ) ) {
+                       if ( ! is_array( $meta ) && !empty( $meta ) ) {
+                               $meta = array( $meta );
+                       }
+
+                       if ( empty( $meta ) ) {
                                /**
                                 * Note: if field is clonable, $meta must be an array with values
                                 * so that the foreach loop in self::show() runs properly

jsor avatar Sep 15 '16 10:09 jsor

Same issue here, tried your code but it doesn't work. Running wp 4.8.3 and the latest version of all metabox.io

alberto-marin avatar Nov 13 '17 13:11 alberto-marin

Hi,

Can you please post your code to create meta boxes?

rilwis avatar Nov 15 '17 01:11 rilwis

<?php

$meta_boxes[] = array(
		"id" => "boardmembers",
		"title" => esc_html__( "Board Members", "metabox-online-generator" ),
		"post_types" => array( "page" ),
		"context" => "advanced",
		"priority" => "default",
		"autosave" => true,
    "show" => array(
      // With all conditions below, use this logical operator to combine them. Default is "OR". Case insensitive. Optional.
      "relation" => "OR",
      // List of page templates (used for page only). Array. Optional.
      "template" => array( "page-about-meet-the-board.php"),
		),
		"fields" => array(
      array(
				"id"     => "members_group",
				// Group field
				"type"   => "group",
				// Clone whole group?
				"clone"  => true,
				// Drag and drop clones to reorder them?
				"sort_clone" => true,
				// Sub-fields
        "group_title" => "Member {#}",
        "collapsible" => true,
				"fields" => array(
    			array(
    				"id" => "{$prefix}member_image",
    				"type" => "image_advanced",
    				"name" => esc_html__( "Members", "metabox-online-generator" ),
    				"desc" => esc_html__( "Add member image", "metabox-online-generator" ),
    				"max_file_uploads" => "1",
    			),
    			array(
    				"id" => "{$prefix}member_name",
    				"type" => "text",
    				"name" => esc_html__( "Name", "metabox-online-generator" ),
    				"desc" => esc_html__( "Add First and Second Name", "metabox-online-generator" ),
    			),
    			array(
    				"id" => "{$prefix}job_title",
    				"type" => "text",
    				"name" => esc_html__( "Job Title", "metabox-online-generator" ),
    				"desc" => esc_html__( "Job Position", "metabox-online-generator" ),
    			),
          array(
    				"id" => "{$prefix}job_description",
    				"type" => "wysiwyg",
            "options" => array(
              "teeny" => true,
              "media_buttons" => false,
              "textarea_rows" => 20,
            ),
    				"name" => esc_html__( "Job Description", "metabox-online-generator" ),
    				"desc" => esc_html__( "Job Description", "metabox-online-generator" ),
    			),
    		),
      ),
    ),
  );
?>

alberto-marin avatar Nov 15 '17 13:11 alberto-marin

Then on my functions.php

<?php
add_filter( 'rwmb_meta_boxes', 'xxx_metaboxes' );

function xxx_metaboxes( $meta_boxes ) {
  $prefix = '_dd_';

  include_once('metaboxes/metabox_frontimage.php');
  include_once('metaboxes/metabox_address.php');
  include_once('metaboxes/metabox_members.php');
  include_once('metaboxes/metabox_products.php');
  include_once('metaboxes/metabox_partners.php');
  include_once('metaboxes/metabox_display_homepage_sections.php');
  include_once('metaboxes/metabox_img_mobile.php');
  include_once('metaboxes/metabox_slider.php');
  include_once('metaboxes/metabox_wysiwyg_with_image.php');
  include_once('metaboxes/metabox_quotes.php');
  include_once('metaboxes/metabox_press_news_image.php');

    return $meta_boxes;
  }
?>

alberto-marin avatar Nov 15 '17 13:11 alberto-marin