Support

Account

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 🙂