Viewing 30 reply threads
  • Author
    Posts
    • #5006
      ndbe
      Participant

      So i go this:

      /*
      Title: Galleries
      Description: 
      Context: normal
      Post Type: project
      Priority: high
      Order: 1
      Collapse: false
      Meta box: true
      */
      
      piklist('field',array(
          'type'=>'group',
          'label' => __('Galleries','ik'),
          'add_more' => true,
          'field' => 'galleries',
          'fields' => array(
              array(
                  'type'=>'text',
                  'field' => 'title',
                  'label' => __('Title', 'ik'),
                  'columns'=>12,
      
              ),
              array(
                  'type'=>'file',
                  'field' => 'photos',
                  'label' => __('Photos','ik'),
                  'options' => array(
                      'button' => __('Add photo','ik')
                  )
      
              ),    
          ),
      ));

      This group is serialized and saved to one custom field.
      Everything works fine at first but problem starts when I delete one of the galleries. Rest of the galleries disappears from edit screen. After a little investigation a found that after removing one of the galleries the resulting array has wrong indexes. It looks like this:

      Before delete
      Array([0]=>[...gallery one...],[1]=>[...gallery two...],[2]=>[...gallery three...])
      And after
      Array([0]=>[...gallery one...],[2]=>[...gallery three...])

      And in the admin panel i can see only gallery with index [0].

    • #5008
      ndbe
      Participant

      After manual change of index directly in DB everything showed up again.

    • #5011
      Steve
      Keymaster

      @ndbe– I can’t reproduce this. Works absolutely fine for me. The indexes reset perfectly on save.

    • #5013
      ndbe
      Participant

      Maybe something is wrong with my code. I will have to look closer.

    • #5020
      ndbe
      Participant

      Can you tell me where in the plugin code is function that should reindex the array?

    • #5021
      ndbe
      Participant

      Clean WordPress install with no plugins, only piklist [0.9.9.4]. After activation of piklist demos in the Add-More’s tab same problem. Serialized groups (“Todo’s (Serialized Group)” and “Newsletter Signup”) don’t reindex and all the elements after element that was deleted are gone.

      Both on server with PHP 5.6.4. Wp_debug set to true returns no errors.

    • #5025
      Steve
      Keymaster

      To make sure we’re both looking at the same thing, would you be able to send some screenshots or a screencast?

      • #5062
        ndbe
        Participant

        Ware you able to replicate this behavior?

    • #5028
      ndbe
      Participant

      Maybe this will help

      Attachments:
      You must be logged in to view attached files.
    • #5075
      Steve
      Keymaster

      @ndbe– I still can’t reproduce. Check out this screencast and let me know if I’m doing it correctly.

    • #5089
      ndbe
      Participant

      Yes exactly the same but in my installation last element vanishes after saving. That’s weird. Can you point me to the part of the plugin that should reindex things?

    • #5134
      Steve
      Keymaster

      This is fixed in the next version of Piklist

    • #5375
      shayneol
      Participant

      Hello Steve,

      I am having the same issue as ndbe. I have an add_more group with a two text boxes and an editor. If I click the plus button to add multiple groups/sections, save the post, then delete any of the middle sections, I have data issues. I have to actually move the section to delete to the bottom of all of the sections (make it the last section), before deleting it. Please see my screencast here for more details: https://dl.dropboxusercontent.com/u/3844293/deleting_addmore-group.mp4

      I have also upgraded to Piklist v.0.9.9.7

      Also, here is the code that I’m using:

      <?php
      /*
      Post Type: drama
      Order: 10
      Priority: high
      Tab: Teacher Page
      Flow: DW Workflow
      */
      
         piklist('field', array(
          'type' => 'group'
      	,'field' => 'teacher_page'
          ,'label' => 'Teacher Pages'
          ,'template' => 'field'
      	,'description' => 'To add more staff members, click the blue "+" button. Click and drag to rearrange the order'
          ,'add_more' => true
          ,'fields' => array(
      	
            array(
              'type' => 'text'
              ,'field' => 'section_title'
              ,'label' => 'Section Title'
              ,'columns' => 6
            )
      
            ,array(
              'type' => 'text'
              ,'field' => 'section_anchor'
              ,'label' => 'Section Anchor ID'
              ,'columns' => 6
            )
      
      	  ,array(
      			'type' => 'editor'
      			,'field' => 'section_content'
      			,'label' => 'Section Content'
      			,'options' => array(
      			  'wpautop' => true
      			  ,'media_buttons' => true
      			  ,'shortcode_buttons' => true
      			  ,'teeny' => false
      			  ,'dfw' => false
      			  ,'tinymce' => array(
      				'resize' => false
      				,'wp_autoresize_on' => true
      			  )
      			  ,'quicktags' => true
      			  ,'drag_drop_upload' => true
      			)
      	  )
      
      	  
          ) // end group: teacher_page
      
        )); // end field declaration
      

      Thanks

    • #5378
      Steve
      Keymaster

      Thanks for the video. It really helped a lot. We’ll get this fixed in the next version while we write our unit tests.

      In the meantime, try saving the data individually, not as an array. Remove this:

      ,'field' => 'teacher_page'
      

      You will have to change your frontend code, but it shouldn’t be a big deal.

      Let me know if that helps.

    • #5381
      shayneol
      Participant

      Hey Steve,

      I’m glad the video helped. I’m a visual learner so I know videos help me better than text sometimes.

      I will hold off on updating my code until the next version is available. The other tabs on this Post Type have multiple add_more groups and I have different theme files that would need to change, all of which were already updated when I upgraded to Piklist 0.9.9 🙂

      The work around of moving the section that I need delete to the bottom first will work in the meantime.

      Thanks for all of your help!

    • #5561
      mcmaster
      Participant

      Steve, I’ve been having this problem for some time. I’ve been able to recover data by editing the serialized string in the database to “close up” the array.

      I just went through that exercise again, but this time there was a twist. The value was double serialized.

      
      s:3388:"a:17:{i:0;a:5:{s:16:"feature_headline";s:17:"Jan Charten-Brawn";s:13:"feature_image";a:1:{i:0;s:3:"330";}s:12:"feature_text";s:9:"President";s:16:"feature_link_url";s:0:"";s:17:"feature_link_text";s:0:"";}
      ...
      i:16;a:5:{s:16:"feature_headline";s:10:"Donny Lane";s:13:"feature_image";a:1:{i:0;s:3:"336";}s:12:"feature_text";s:8:"Director";s:16:"feature_link_url";s:0:"";s:17:"feature_link_text";s:0:"";}}";
      

      I had to remove the extra serialization wrapper in addition to fixing the indices:

      
      a:17:{i:0;a:5:{s:16:"feature_headline";s:17:"Jan Charten-Brawn";s:13:"feature_image";a:1:{i:0;s:3:"330";}s:12:"feature_text";s:9:"President";s:16:"feature_link_url";s:0:"";s:17:"feature_link_text";s:0:"";}
      ...
      i:16;a:5:{s:16:"feature_headline";s:10:"Donny Lane";s:13:"feature_image";a:1:{i:0;s:3:"336";}s:12:"feature_text";s:8:"Director";s:16:"feature_link_url";s:0:"";s:17:"feature_link_text";s:0:"";}}
      

      Hope this may be helpful to someone else as we wait for 1.0. 😉

      Donna

    • #5848
      bjoerns
      Participant

      Hi Donna

      Just the same for me. What’s even more strange: If I use the following group field for standard posts, then it gets wrong serialized, but despite of that its data shows up correctly. If I use the field in a custom post type (for the event custom post type of https://de.wordpress.org/plugins/events-manager/), then its data doesn’t show up.

      <?php
      /*
      Title: Weitere Durchführungstage
      Post Type: event
      Context: side
      Priority: high
      Order: 2
      Meta box: true
      */
      
      piklist('field', array(
          'type' => 'group'
          ,'field' => 'weitere_tage'
          ,'scope' => 'post_meta'
          ,'description' => 'An welchen weiteren Tagen findet dieser Kurs statt?'
          ,'columns' => '12'
          ,'add_more' => true
          ,'fields' => array(
              array(
                  'type' => 'datepicker'
                  ,'label' => __('Datum')
                  ,'scope' => 'post_meta'
                  ,'field' => 'weiterer_tag_datum'
                  ,'attributes' => array(
                      'class' => 'text'
                  )
                  ,'options' => array(
                      'dateFormat' => 'dd.mm.yy'
                  ,'firstDay' => '1'
                  ,'changeYear' => true
                  ,'yearRange' => "-0:+5"
                  ,'changeMonth' => true
                  ,'constrainInput' => true
                  ,'monthNamesShort' => [ "Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez" ]
                  ,'dayNamesMin' => [ "So", "Mo", "Di", "Mi", "Do", "Fr", "Sa" ]
                  )
                  ,'columns' => '6'
              )
              ,array(
                  'type' => 'text'
                  ,'field' => 'weiterer_tag_beginn'
              ,'scope' => 'post_meta'
                  ,'label' => __('Start')
                  ,'value' => '08:00'
                  ,'columns' => '3'
              )
              ,array(
                  'type' => 'text'
                  ,'field' => 'weiterer_tag_ende'
              ,'scope' => 'post_meta'
                  ,'label' => __('Ende')
                  ,'value' => '17:00'
                  ,'columns' => '3'
                  )
          )
      ));
    • #5853
      Steve
      Keymaster

      @bjoerns– Try removing all the scope parameters. You don’t need them in the admin. Piklist auto detects it. See if that helps.

    • #5865
      bjoerns
      Participant

      Thanks for the hint, Steve. But it doesn’t work. I made a 2-minute-screencast, which shows, what’s happening: Youtube.

    • #5954
      efegue
      Participant

      This is probably the same problem I had. Events Manager PRO serializes all the meta values, and piklist also does this, so you get a double serialized value.

      The solution we found was to unserialized Events Manager serialization for our piklist fields.
      Use the hook em_event_save_meta_pre, on this hook check for your field, something like this:

      function HOOK_FUNCTION_event_save_meta_pre($event) {
        if (!empty($event->event_attributes['weitere_tage'])) {
          $event->event_attributes['weitere_tage'] = /* unserialize the value here */;
        }
      }

      Hope it helps!

    • #5960
      nakanaa
      Participant

      @Steve any ETA on when we will the patched version be released? I’m having the same problem with Piklist 0.9.9.7

      BTW, what is the correct way to filter/edit post metadata before it’s saved in the DB?
      In native WP there’s wp_insert_post_data, but I tried using it but the $data array doesn’t have any of the metadata included. Where should I look?

      I made a temporary fix for this issue, but I had to edit Piklist plugin files because I couldn’t figure how to filter the metadata. If anyone is interested, here’s how I fixed it:

      First defined this somewhere:

      
      /*
       * Custom fix for: https://piklist.com/support/topic/0-9-9-6-add-more-problem/
       *
       * TODO: Remove when fixed upstream!
       */
      function fix_keys(&$value) {
          if (is_array($value)) {
              // Check whether the array has numeric keys
              // From: http://stackoverflow.com/a/4254008
              if (!(count(array_filter(array_keys($value), 'is_string')) > 0)) {
                  $value = array_values($value);
              }
              foreach ($value as &$item) {
                  fix_keys($item);
              }
          }
      }
      

      Then at piklist\includes\class-piklist-form.php after line 3111 (beginning of the else clause) I added this:

      
      if ($field['type'] === 'group' && is_array($field['request_value'])) {
          fix_keys($field['request_value']);
      }
      

      No idea if it’s optimal in any way, but at least everything seems to work now (only did some quick tests).

    • #5976
      bjoerns
      Participant

      @efegue: Your solution hint is very appreciated. Thanks for it. I found another thread from August 2015, where the solution is very similar. The only difference: It uses the unset-function, so that the field gets ignored by the Events Manager-Post Meta-Save-Function:

      add_action('em_event_save_meta_pre', 'prevent_double_serialization_by_em_and_piklist');
      function prevent_double_serialization_by_em_and_piklist($event) {
          unset( $event->event_attributes['field_name_of_the_piklist_add_more_field'] );
      }

      @sbruner: I think this topic can be marked as resolved with the exception of the post 5960 from nakanaa above.

    • #5985
      ndbe
      Participant

      if someone is struggling with original issue (lost add more items after remove) try this:
      in file piklist.js (parts/js folder) around line 1495 change this code:

      $this.re_index($wrapper.parent(), true);
      
                  $wrapper
                    .trigger('piklistaddmore', [$wrapper, 'remove'])
                    .remove();

      to this:

            var $parent = $wrapper.parent();
      
                  $wrapper
                    .trigger('piklistaddmore', [$wrapper, 'remove'])
                    .remove();
                    
                    $this.re_index($parent, true);

      It looks like this little patch fixed the issue for me.

    • #6016
      Sander Schat
      Participant

      yes, exactly the same problem here! keys where off after ‘deleting’ some items in an add_more group

      And the quick fix from user ndbe seems to work.

      Hooraayy for this sharing ; )

    • #6478
      notaname
      Participant

      Still not fixed in 0.9.9.8, use fix_keys function from nakanaa.

    • #7190
      chrisatoddball
      Participant

      I’m getting this problem in 0.9.9.9.

      Have used CSS to disable the +/- buttons on all but the last add_more. Have kept sorting on, so user can drag an add_more to the bottom and then delete it.

    • #7224
      Steve
      Keymaster

      This seems to be an issue with group add_more fields only. Let us know if you see it in just simple add_mores, and then post your field here.

    • #7459
      zsoltr
      Participant

      Using 0.9.9.9 and ‘type’ => ‘group’, nakanaa’s fix worked.

    • #7608
      hirschbrat
      Participant

      Any news when this bug will be fixed? I have the same problem in v 0.9.9.9.

      Here my add-more field code:

        piklist('field', array(
          'type' => 'group'
          ,'label' => 'Warenkorb'
          ,'field' => 'fvb_order_cart'
          ,'add_more' => true
          ,'fields' => array(
              array(
                  'type' => 'select'
                  ,'field' => 'product'
                  ,'label' => 'Produkt'
                  ,'columns' => 6
                  ,'choices' => $choices
                  ,'conditions' => $conditions
              )
              ,array(
                  'type' => 'number'
                  ,'field' => 'price'
                  ,'label' => 'Preis [EUR]'
                  ,'columns' => 3
                  ,'value' => '0.00'
                  ,'description' => 'This field is updated by the Select field above'
                  ,'attributes' => array(
                      'min' => -10000
                      ,'step' => 0.01
                  )  
              )
              ,array(
                  'type' => 'number'
                  ,'field' => 'number'
                  ,'label' => 'Anzahl'
                  ,'columns' => 2
                  ,'value' => 1
                  ,'description' => 'This field is updated by the Select field above'
              )
          )
          ,'validate' => array(
            array(
              'type' => 'fvb_resource'
              ,'options' => array(
                  'resource' => 'cart'
              )
            )
          )
        ));
    • #7877
      hirschbrat
      Participant

      Still the same problem in 0.9.9.10.

      The fix from ndbe worked for me, but i always have to edit the pickles.js after a piklist update. Can you include this fix to the next piklist release?

      in file piklist.js (parts/js folder) around line 1495 change this code:

      
      $this.re_index($wrapper.parent(), true);
      
                  $wrapper
                    .trigger('piklistaddmore', [$wrapper, 'remove'])
                    .remove();
      

      to this:

      
            var $parent = $wrapper.parent();
      
                  $wrapper
                    .trigger('piklistaddmore', [$wrapper, 'remove'])
                    .remove();
                    
                    $this.re_index($parent, true);
      
      • #7878
        Steve
        Keymaster

        Can you try this instead of see if it still fixes the issue? There is a slight problem with ndbe’s code:

        if (count > 0)
                  {
                    var $sortable = $wrapper.parent(),
                      $containers = $sortable.children('div.piklist-field-addmore-wrapper');
        
                    $wrapper
                      .trigger('piklistaddmore', [$wrapper, 'remove'])
                      .remove();
        
                    $this.re_index($sortable, true);
                  }
    • #7879
      hirschbrat
      Participant

      @Steve

      I tried your code and it worked for me, too.

      • #7880
        Steve
        Keymaster

        Great. I’ll include that in the next version. Thanks!

    • #7881
      Steve
      Keymaster

      This will updated in the next version of Piklist

Viewing 30 reply threads
  • The topic ‘[0.9.9.6] Add more problem’ is closed to new replies.