- This topic has 33 replies, 12 voices, and was last updated 4 years, 10 months ago by
Steve.
-
AuthorPosts
-
-
November 17, 2015 at 10:30 am #5006
ndbeMemberSo 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].
-
November 17, 2015 at 10:51 am #5008
ndbeMemberAfter manual change of index directly in DB everything showed up again.
-
November 17, 2015 at 11:26 am #5011
-
November 17, 2015 at 11:56 am #5013
ndbeMemberMaybe something is wrong with my code. I will have to look closer.
-
November 18, 2015 at 5:11 am #5020
ndbeMemberCan you tell me where in the plugin code is function that should reindex the array?
-
November 18, 2015 at 5:29 am #5021
ndbeMemberClean 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.
-
November 18, 2015 at 11:19 am #5025
SteveKeymasterTo make sure we’re both looking at the same thing, would you be able to send some screenshots or a screencast?
-
November 18, 2015 at 11:39 am #5028
-
November 23, 2015 at 12:31 pm #5075
SteveKeymaster@ndbe– I still can’t reproduce. Check out this screencast and let me know if I’m doing it correctly.
-
November 24, 2015 at 7:36 am #5089
ndbeMemberYes 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?
-
November 27, 2015 at 5:06 pm #5134
SteveKeymasterThis is fixed in the next version of Piklist
-
December 17, 2015 at 5:45 pm #5375
shayneolMemberHello 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 declarationThanks
-
December 18, 2015 at 11:12 am #5378
SteveKeymasterThanks 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.
-
December 18, 2015 at 5:07 pm #5381
shayneolMemberHey 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!
-
January 11, 2016 at 7:07 pm #5561
mcmasterMemberSteve, 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
-
February 5, 2016 at 10:52 am #5848
bjoernsMemberHi 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' ) ) )); -
February 5, 2016 at 1:55 pm #5853
-
February 6, 2016 at 4:28 am #5865
-
February 18, 2016 at 6:40 am #5954
efegueMemberThis 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 hookem_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!
-
February 20, 2016 at 12:23 pm #5960
nakanaaMember@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).
-
February 21, 2016 at 3:09 am #5976
bjoernsMember@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. -
February 23, 2016 at 5:24 am #5985
ndbeMemberif 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.
-
February 29, 2016 at 9:02 am #6016
Sander SchatMemberyes, 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 ; )
-
May 10, 2016 at 8:43 pm #6478
notanameMemberStill not fixed in 0.9.9.8, use fix_keys function from nakanaa.
-
August 18, 2016 at 8:30 am #7190
chrisatoddballParticipantI’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.
-
August 23, 2016 at 11:05 am #7224
SteveKeymasterThis seems to be an issue with
groupadd_morefields only. Let us know if you see it in just simple add_mores, and then post your field here. -
October 24, 2016 at 10:35 am #7459
zsoltrMemberUsing 0.9.9.9 and ‘type’ => ‘group’, nakanaa’s fix worked.
-
December 3, 2016 at 8:51 am #7608
hirschbratMemberAny 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' ) ) ) )); -
March 31, 2017 at 1:00 pm #7877
hirschbratMemberStill 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);-
March 31, 2017 at 1:49 pm #7878
SteveKeymasterCan 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); }
-
-
March 31, 2017 at 2:08 pm #7879
hirschbratMember@Steve
I tried your code and it worked for me, too.
-
March 31, 2017 at 2:26 pm #7881
SteveKeymasterThis will updated in the next version of Piklist
-
-
AuthorPosts
- The topic ‘[0.9.9.6] Add more problem’ is closed to new replies.