Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image_advanced field inside group disappears on save #922

Open
sebgrey opened this issue Jul 12, 2016 · 5 comments
Open

image_advanced field inside group disappears on save #922

sebgrey opened this issue Jul 12, 2016 · 5 comments

Comments

@sebgrey
Copy link

sebgrey commented Jul 12, 2016

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.

@jsor
Copy link

jsor commented Sep 15, 2016

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

@alberto-marin
Copy link

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

@rilwis
Copy link
Member

rilwis commented Nov 15, 2017

Hi,

Can you please post your code to create meta boxes?

@alberto-marin
Copy link

<?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
Copy link

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;
  }
?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants