Support

Account

Home Forums Add-ons Repeater Field Translate date inside Repeater field.

Solved

Translate date inside Repeater field.

  • Hi, I need some guidance to do the following:

    I have a repeater field called dates, inside I have a Date Time Picker subfield called dates. I need to change the date format to j \d\e\ F G hs\h\s\, this will show the date as 23 de august 17hs (Spanish date/time format) and I need to use the date_i18n function to translate the month, as it appears in English.
    I successfully translated the dates using a single Date Time Picker field, but I don’t know how to do the same using a Repeater field.

    Thanks in advanced.

  • To do this with a repeater field it would look something like this, and I will include information from your other topic.

    
    if (have_row('repeater_field_name')) {
      $dates = array();
      while(have_row('repeater_field_name')) {
        the_row();
        $date = get_sub_field('date_subfield_name');
        if ($date) {
          $dates[] = date_i18n('j \d\e\ F \-\ G \h\s', strtotime($date_3));
        }
      } // end while have rows
      if ( $dates) {
        echo '<h5>UPCOMING EVENTS</h5><p> ' . implode(' | ', $dates) . '</p>';
      }
    } // end if have rows
    
  • I tried this and it gives me the following error > FATAL ERROR: CALL TO UNDEFINED FUNCTION HAVE_ROW()

    I’m sure I’m doing something wrong, this is the code:

    function adb_display_custom_fields() {
    echo '<div class="curso-meta">';
    if (have_row('dates')) {
    $dates = array();
    while(have_row('dates')) {
    the_row();
    $date = get_sub_field('date');
    if ($date) {
    $dates[] = date_i18n('j \d\e\ F \-\ G \h\s', strtotime($date));
    }
    } // end while have rows
    if ( $dates) {
    echo '<h5>UPCOMING EVENTS</h5><p> ' . implode(' | ', $dates) . '</p>';
    }
    } // end if have rows
    echo '</div>';
    }
  • sorry, that’s a typo on my part, it should be have_rows()

    
    if (have_rows('repeater_field_name')) {
      $dates = array();
      while(have_rows('repeater_field_name')) {
        the_row();
        $date = get_sub_field('date_subfield_name');
        if ($date) {
          $dates[] = date_i18n('j \d\e\ F \-\ G \h\s', strtotime($date_3));
        }
      } // end while have rows
      if ( $dates) {
        echo '<h5>UPCOMING EVENTS</h5><p> ' . implode(' | ', $dates) . '</p>';
      }
    } // end if have rows
    
  • Ok, the error is fixed but it only shows the third date, date1 and date2 display today’s date and time. I replaced $date_3 with $date, is that ok?

    UPDATE > I think the date problem is because is inverting the day/month. If the calendar shows 27/09/2016 (September 27), it reads the day as 27 and the month doesn’t exist, if I pick 09/10/2016 (October 09) it displays as September 10. I inverted the formats in the field settings (to m/d/y) and now it works.

  • I think that the date_i18n() function in incorrectly translating the dates, possibly because of the format of the date that’s being returned by ACF.

    Try getting the raw data from the date field without formatting by setting the 3rd parameter like this. get_sub_field('date', false, false);

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.