Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter xarz

    (@xarz)

    Solved modifying the post-custom-field.php template.

    <?php
    
    //extract styles & classes
    extract($extra_attr);
    ?>
    
    <div class="<?php echo esc_attr( $wrapper_class ); ?>" <?php if ( !empty($wrapper_style) ) { ?> style="<?php echo esc_attr($wrapper_style); ?>" <?php } ?>>
        <?php if ( !empty($attributes['customField'] ) ) {
    		/* ORIGINAL CODE
            echo get_post_meta( get_the_ID(), esc_attr( $attributes['customField'] ), true ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
            */
            $cfield=get_post_meta( get_the_ID(), esc_attr( $attributes['customField'] ), true );
            if (!empty($cfield)){
                if(strlen($cfield) == 2){    
                    $term= get_term($cfield);
                    echo $term->slug;
                }else {
                    if (strlen($cfield)==8){
                        $year=substr($cfield,0,4);
                        $month=substr($cfield,4,2);
                        setlocale(LC_TIME, 'es_ES.UTF-8');   
                        $dateObj   = DateTime::createFromFormat('!m', $month);
                        $timestamp=strtotime($cfield);
                        echo date_i18n("F Y ",$timestamp);                    
                    }
                }
            }
        } ?>
    </div>
    
    Thread Starter xarz

    (@xarz)

    Marking as solved, please.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom field block hows date not formated from an ACF field’ is closed to new replies.