Tagged: 

Viewing 8 reply threads
  • Author
    Posts
    • #4204
      anagram
      Member

      I 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?

    • #4205
      Steve
      Keymaster

      @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.

    • #4206
      anagram
      Member

      Hello 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.
    • #4209
      Steve
      Keymaster

      @anagram– That’s odd. I just tested and it worked fine. Let’s try a few things.

      1) Make sure the field name is unique and the only field with this name. Try changing it to anagram_recurrence_dates.
      2) Remove the scope parameter. Piklist can auto detect.
      3) Verify you are running the latest version of Piklist. Version 0.9.4.27

      If none of these fix the issue, please zip up all your code and email to [email protected]

    • #4210
      anagram
      Member

      I 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!

    • #4211
      Steve
      Keymaster

      Please keep us updated on what you find.

    • #4212
      anagram
      Member

      Ok, 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'
    • #4213
      Steve
      Keymaster

      Good find! Please send us the link to that plugin so we can continue to test against it.

    • #4214
      anagram
      Member

      Wordpres URL of plugin

      https://wordpress.org/plugins/events-manager/

      Plugin Website:

      http://wp-events-plugin.com/

      I now use em_event_save_pre instead of em_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.

Viewing 8 reply threads
  • The topic ‘datepicker & add_more – all entries have the same date’ is closed to new replies.