 wen-taoL
|
I am trying to:
Display date in english in any language
hidden link
Link to a page where the issue can be seen:
hidden link
I expected to see:
Date must be 7 July 15, 202
Instead, I got:
7月 15, 2022
|
 Nigel
WPML Supporter since 02/2016
Timezone:
Europe/Madrid (GMT+02:00)
|
Hi there
Can I check, how are you outputting the date?
Simply using the ACF function "the_field" in the theme PHP template? Or some other way?
|
 wen-taoL
|
Sorry I am using get_field
$date = get_field('date');
echo $date;
like this. Also I dont see chat feature on your support. How can i access chat feature for the support?
|
 Nigel
WPML Supporter since 02/2016
Timezone:
Europe/Madrid (GMT+02:00)
|
Chat support is offered when you create a new ticket if there are supporters available to provide it at that time.
Regarding the issue you describe (which is the expected behaviour, dates are output in the format of the current locale), the ACF date field stores the field value in wp_postmeta in the format "yyyymmdd" (e.g. for today that would be "20220713").
When you use the function get_field it returns the formatted value based upon the current locale (and the format you specify in the ACF settings for the field).
Note this has nothing to do with WPML per se, you would see the same if you disabled WPML plugins and changed the site language and checked the results on the front end. For each language the date would be formatted according to the locale.
If you want something different than this standard behaviour you will need some custom code to generate the date in the required format, ignoring the current locale.
You will want to retrieve the unformatted value of the date field (so the $format_value parameter should be set to false: hidden link).
Convert that to a timestamp with strtotime (hidden link).
Then format that without making any allowance for the locale, with the date function (hidden link).
Your code should probably look something like this (not sure if you have the post ID already available):
global $post;
$date = get_field('date', $post->ID, false);
$date_timestamp = strtotime( $date );
$date_formatted = date( "F j, Y", $date_timestamp );
echo $date_formatted;
|