Tagged: add_more
- This topic has 8 replies, 2 voices, and was last updated 6 years, 5 months ago by
anagram.
-
AuthorPosts
-
-
August 15, 2015 at 8:11 am #4204
anagramMemberI need a field (named it recurrence_dates) which can hold multiple dates (I’m using a datepicker field with add_more option enabled)
This works fine, besides the fact, that all datepicker are displaying the same date.
I looked into the database and this is what is contained in the wp_postmeta table:
‘268845’, ‘19439’, ‘rec_dates’, ‘a:3:{i:0;s:7:\”8.18.15\”;i:1;s:6:\”8.9.15\”;i:2;s:7:\”8.10.15\”;}’
‘268846’, ‘19439’, ‘rec_dates’, ‘a:3:{i:0;s:7:\”8.18.15\”;i:1;s:6:\”8.9.15\”;i:2;s:7:\”8.10.15\”;}’
‘268847’, ‘19439’, ‘rec_dates’, ‘a:3:{i:0;s:7:\”8.18.15\”;i:1;s:6:\”8.9.15\”;i:2;s:7:\”8.10.15\”;}’I tried already:
– different date formats
– serialize=[true|false]but nothing worked. all entries become the same.
my configuration:
/*
Title: Erweiterte Eventeinstellungen
Description: Hier können weitere Details zu den Events gepflegt werden.
Capability: edit_pages
Locked: true
Collapse: false
Post Type: event,event-recurring
*/piklist(‘field’, array(
‘type’ => ‘datepicker’
,’scope’ => ‘post_meta’ // Not used for settings sections
,’field’ => ‘recurrence_dates’
,’label’ => ‘Wiederholung nach Datum’
,’description’ => ‘Der Termin wird an folgenden Daten wiederholt’
,’options’ => array(
‘dateFormat’ => ‘m.d.y’
,’firstDay’ => ‘0’
)
,’add_more’ => true
));any ideas?
-
August 15, 2015 at 9:07 am #4205
SteveKeymaster@anagram– For a simple add-more like this, the data is stored in a one-dimensional array. You can just pull the data and loop through it, like this:
$dates = get_post_meta(get_the_id(), 'recurrence_dates'); foreach ($dates as $date => $value) { echo $value; }Let me know if that works for you.
-
August 15, 2015 at 10:20 am #4206
anagramMemberHello Steve,
thx for the quick reply.
I saw already that the data is actually correctly stored (but also duplicated n times where n entries exists)
But the admin area is not usable like this.
See the file: before_saving.jpg (This is how i enter the data, in this case dates from 1st to 3rd of august.
See the file: after_saving.jpg (This is how it looks after i store the article)
The data stored in the db looks like this
270131 19610 recurrence_dates a:3:{i:0;s:11:"Aug 1, 2015";i:1;s:11:"Aug 2, 2015";i:2;s:11:"Aug 3, 2015";}
270132 19610 recurrence_dates a:3:{i:0;s:11:"Aug 1, 2015";i:1;s:11:"Aug 2, 2015";i:2;s:11:"Aug 3, 2015";}
270133 19610 recurrence_dates a:3:{i:0;s:11:"Aug 1, 2015";i:1;s:11:"Aug 2, 2015";i:2;s:11:"Aug 3, 2015";}
It seems it always shows the last entry.
So it’s not really usable this way. Am i doing something wrong?
Attachments:
You must be logged in to view attached files. -
August 15, 2015 at 10:57 am #4209
SteveKeymaster@anagram– That’s odd. I just tested and it worked fine. Let’s try a few things.
1) Make sure the
fieldname is unique and the only field with this name. Try changing it toanagram_recurrence_dates.
2) Remove thescopeparameter. Piklist can auto detect.
3) Verify you are running the latest version of Piklist. Version 0.9.4.27If none of these fix the issue, please zip up all your code and email to [email protected]
-
August 15, 2015 at 11:01 am #4210
anagramMemberI think i found the cause of the problem. Just tested with a plain text field – same problem.
As i’m pretty sure this would cause a lot of support tickets and be probably fixed already there must be another problem.
I’m using events-manager, so i’m pretty sure it’s events manager in combination with piklist that causes the problems.
I’m investigating further and will a short answer if i find a solution.
Seeing it form piklist point of view: ticket can be closed.
thx for your effort. great framework, thumbs up!
-
August 15, 2015 at 11:14 am #4211
SteveKeymasterPlease keep us updated on what you find.
-
August 15, 2015 at 11:40 am #4212
anagramMemberOk, i found a workaround.
There’s a hook that is called before the metadata is stored by events-manager: em_event_save_meta_pre
I just unset the recurrence_dates there.
– The problem occurs only for multiple entries (add_more)
– The solution is dirty: adding another repeating field will require adapting this method. As I’m not planning to do add a lot of fields, the solution is ok for me.add_action('em_event_save_meta_pre', 'agram_em_event_save_meta_pre'); function agram_em_event_save_meta_pre($event) { unset( $event->event_attributes['recurrence_dates'] ); }Entries in the db look now like this
'270242', '19633', 'recurrence_dates', 'Aug 16, 2015' '270243', '19633', 'recurrence_dates', 'Aug 17, 2015' -
August 15, 2015 at 12:05 pm #4213
SteveKeymasterGood find! Please send us the link to that plugin so we can continue to test against it.
-
August 15, 2015 at 12:17 pm #4214
anagramMemberWordpres URL of plugin
https://wordpress.org/plugins/events-manager/
Plugin Website:
I now use
em_event_save_preinstead ofem_event_save_meta_pre(this one is executed much earlier).Everything now works as expected. Thx a lot Steve for your insight and sorry, should have tested it with a normal post first. The idea came to my mind a bit late.
-
-
AuthorPosts
- The topic ‘datepicker & add_more – all entries have the same date’ is closed to new replies.