Home Forums Front-end Issues Date picker language front-end


Date picker language front-end

  • Hithere

    I’m having problems with the date picker field. I use it to set a date of events, a custom post type.

    My WordPress installation is in Dutch (Multisite) and whatever i try i keep getting the dates back in English format in my theme. I want to retrieve the 3 letter month name in dutch;

    <?php $date = DateTime::createFromFormat(‘Ymd’, get_field(‘datum_event’)); echo $date->format(‘M’); ?>

    The date picker in the admin area is in Dutch….

    Hope someone can help.

    Kind regards!
    Floris Hermans

  • Hi @floriz

    This is an interesting issue which I would like to solve and write a tutorial for.
    Here is an older thread which covered some ideas / solutions:

    I wonder if it is posisble to use the WP __() translate function to translate the month like so:

    $month = $date->format(‘M’);
    echo __($month);
  • Ok, solved it now. Not the most beautiful solution but it works:

    <?php if (have_posts()) :

    $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1;
    $today = date( ‘Ymd’, strtotime( ‘-1 day’ ) );

    query_posts( array(
    ‘post_type’ => ‘agenda’,
    ‘meta_key’ => ‘datum_event’,
    ‘orderby’ => ‘meta_value_num’,
    ‘order’ => ‘ASC’,
    ‘posts_per_page’ => 12,
    ‘paged’ => $paged,

    ‘meta_query’ => array(
    ‘key’ => ‘datum_event’,
    ‘meta-value’ => $today,
    ‘value’ => $today,
    ‘paged’ => $paged,

    ) );

    date_default_timezone_set( ‘Europe/Amsterdam’ );
    setlocale( LC_ALL, ‘nl_NL’ ) or setlocale( LC_ALL, ‘nld_NLD’ );

    $months = explode( ‘,’, ‘,jan,feb,mrt,apr,mei,jun,jul,aug,sep,okt,nov,dec’ );

    while (have_posts()) : the_post();

    $date = DateTime::createFromFormat( ‘Ymd’, get_field( ‘datum_event’ ), new DateTimeZone( ‘Europe/Amsterdam’ ) );

    <p class=”jaar”><?php echo $date->format( ‘Y’ ); ?></p>
    <p class=”dag”><?php echo $date->format( ‘j’ ); ?></p>
    <p class=”maand”><?php echo $months[ $date->format( ‘n’ ) ]; ?></p>

  • it would be so much better if it just uses the WordPress language settings as standard output.

  • Hi @floriz

    Thanks for the code. I’m sure there is a function in the WP core for us to use in this scenario, I’m just not sure which one…

    Thanks again.

  • Hi Floris,
    i had the same problem 2 days ago with a german language website and i`ve found a simple solution.
    please see here: (first column, Mrz stands for März)

    here is the solution i have used:

    $dateStart = date_i18n("d M Y", strtotime(get_sub_field('stcksch_termine_datum1')));
    <?php if(get_sub_field('stcksch_termine_datum1')): ?>
    <?php echo $dateStart; ?>	
    <?php endif; ?>

    hope it helps.


    EDIT: i have used it as a subfield in a repeater field, so please use get_field instead of get_sub_field.

  • Hi, my date picker field is still not getting the translated value after using the snippet above. I have read this could be a bug after WordPress 5.3?

    I am using WordPress 5.5 + ACF PRO 5.9.0 + Polylang Pro 2.8.1 and the following code:

    wp_date("F Y", strtotime(get_sub_field('date')));

    wp_date is the alternative to date_i18n after WordPress 5.3. date_i18n is giving me the month text only in English too.

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

The topic ‘Date picker language front-end’ is closed to new replies.