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


Date picker language front-end

    • floriz

    • September 6, 2013 at 2:39 pm


    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

    • Elliot

    • September 7, 2013 at 1:52 pm

    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);
    • floriz

    • September 7, 2013 at 2:28 pm

    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>

    • floriz

    • September 7, 2013 at 2:30 pm

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

    • Elliot

    • September 8, 2013 at 6:11 pm

    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.

    • andiszek

    • September 15, 2013 at 7:14 pm

    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.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.