Support

Account

Home Forums General Issues Displaying shortcode of date_picker with format Reply To: Displaying shortcode of date_picker with format

  • Hi ! I also add an error generated with the above code, so I modified it using the date_i18n function so the date will be translated corresponding to your language. (it worked with wpml)

    Please note that for this to work, the format of your acf date field (for template) must be this type :
    20211010 Ymd

    As above, the syntax of the Shortcode is the same :
    [acf_date field='date_field' date_format='M j, Y']

    function acf_date_shortcode( $atts )
    {
    extract( shortcode_atts( array(
    		'field'			=> '',
    		'post_id'		=> false,
    		'format_value'	=> true,
    		'date_format' 	=> ''
    	), $atts ) );
    	
    	$acf_date = get_field( $field, $post_id, $format_value );
    	
    	$value = date_i18n( $date_format,strtotime($acf_date) );
    		return $value;
    }
    add_shortcode( 'acf_date', 'acf_date_shortcode' );