Home › Forums › General Issues › Displaying shortcode of date_picker with format › Reply To: Displaying shortcode of date_picker with format
Hi @spinline
This is not possible with the acf shortcode.
May be you could consider implementing your own shortcode for implementing this. The code would be simple, It will look something like this:
function acf_date_shortcode( $atts )
{
// extract attributs
extract( shortcode_atts( array(
'field' => '',
'post_id' => false,
'format_value' => true,
'date_format' => ''
), $atts ) );
$acf_date = get_field( $field, $post_id, $format_value );
$date = DateTime::createFromFormat('d/m/Y', $acf_date);
$value = $date->format($date_format);
return $value;
}
add_shortcode( 'acf_date', 'acf_date_shortcode' );
and on the usage, it would be something like this: [acf_date field='date_field' date_format='M j, Y']
For this code to work, the return date for the date field should be of this format: d/m/Y
Hope this helps 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.