duanguzhong5776 2017-06-15 13:08
浏览 27
已采纳

如何在wordpress中自定义自定义发布日期格式?

I've used custom field on my event called date. I want to display this date as: MAY 23, 2017. But it's displaying as: 20170523. I've used this code.

<?php the_field( 'date' ); ?>
  • 写回答

1条回答 默认 最新

  • duanpin9531 2017-06-15 13:19
    关注

    Are you using Advanced Custom Fields PRO? If yes, then you can try this:

    <?php
    $time = strtotime( get_field( 'date' ) );
    $date = date( 'F d, Y', $time );
    
    echo $date;
    ?>
    

    More native way for Advanced Custom Fields PRO would be the following:

    <?php
    $date = get_field( 'date', false, false );
    $date = new DateTime( $date );
    
    echo $date->format('F d, Y');
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?