Php 如何从ACF日期选择器月份获取前3个字符?

Php 如何从ACF日期选择器月份获取前3个字符?,php,advanced-custom-fields,laravel-blade,Php,Advanced Custom Fields,Laravel Blade,我正在尝试格式化从ACF日期选择器字段返回的日期。目前,它返回的日期为('F d,y'),显示为2018年10月16日。但是,我希望它显示为2018年10月16日 基本上剥离月份字符串,仅显示前3个字符。有什么想法吗 查看: @if(!empty($posts)) @include('layouts.posts', $posts) @else <p>No Events to show</p> @endif <div class="post-items"

我正在尝试格式化从ACF日期选择器字段返回的日期。目前,它返回的日期为('F d,y'),显示为2018年10月16日。但是,我希望它显示为2018年10月16日

基本上剥离月份字符串,仅显示前3个字符。有什么想法吗

查看:

@if(!empty($posts))
    @include('layouts.posts', $posts)
@else
  <p>No Events to show</p>
@endif
<div class="post-items">
    @if ( count($posts) > 0)
      @foreach ($posts as $key => $post)
        <div class="post-item" >
            @if ($post['date'] != '')
                <div class="post-item__date">
                    {!! $post['date'] !!}
                </div>
            @endif
            {!! $post['content']!!}
      </div><!-- .post-item -->
      @endforeach
    @endif
</div>
public function posts() {
$posts = [];

foreach ($this->wp_query->posts as $key => $post) {

    $posts[$key]['date'] = get_field('acf__event_date', $post->ID);
    $posts[$key]['content'] =
                '
            <h2>'.$post->post_title.'</h2>
            <p>'.wp_trim_words(get_post_field('post_content', $post->ID), 30).'</p>
            <p><a href="'.get_permalink($post->ID).'" class="button">Read more</a></p>';
}

return $posts;
}
@if(!empty($posts))
@包括('layouts.posts',$posts)
@否则
没有要显示的事件

@恩迪夫
布局。帖子:

@if(!empty($posts))
    @include('layouts.posts', $posts)
@else
  <p>No Events to show</p>
@endif
<div class="post-items">
    @if ( count($posts) > 0)
      @foreach ($posts as $key => $post)
        <div class="post-item" >
            @if ($post['date'] != '')
                <div class="post-item__date">
                    {!! $post['date'] !!}
                </div>
            @endif
            {!! $post['content']!!}
      </div><!-- .post-item -->
      @endforeach
    @endif
</div>
public function posts() {
$posts = [];

foreach ($this->wp_query->posts as $key => $post) {

    $posts[$key]['date'] = get_field('acf__event_date', $post->ID);
    $posts[$key]['content'] =
                '
            <h2>'.$post->post_title.'</h2>
            <p>'.wp_trim_words(get_post_field('post_content', $post->ID), 30).'</p>
            <p><a href="'.get_permalink($post->ID).'" class="button">Read more</a></p>';
}

return $posts;
}

@如果(计数($posts)>0)
@foreach($key=>$post)
@如果($post['date']!='')
{!!$post['date']
@恩迪夫
{!!$post['content']!!}
@endforeach
@恩迪夫
控制器:

@if(!empty($posts))
    @include('layouts.posts', $posts)
@else
  <p>No Events to show</p>
@endif
<div class="post-items">
    @if ( count($posts) > 0)
      @foreach ($posts as $key => $post)
        <div class="post-item" >
            @if ($post['date'] != '')
                <div class="post-item__date">
                    {!! $post['date'] !!}
                </div>
            @endif
            {!! $post['content']!!}
      </div><!-- .post-item -->
      @endforeach
    @endif
</div>
public function posts() {
$posts = [];

foreach ($this->wp_query->posts as $key => $post) {

    $posts[$key]['date'] = get_field('acf__event_date', $post->ID);
    $posts[$key]['content'] =
                '
            <h2>'.$post->post_title.'</h2>
            <p>'.wp_trim_words(get_post_field('post_content', $post->ID), 30).'</p>
            <p><a href="'.get_permalink($post->ID).'" class="button">Read more</a></p>';
}

return $posts;
}
公共职能岗位(){
$员额=[];
foreach($this->wp\u query->posts as$key=>$post){
$posts[$key]['date']=get_字段('acf_u事件_日期',$post->ID);
$posts[$key]['content']=
'
“.$post->post_title”
“.wp_trim_words(get_post_字段('post_content',$post->ID),30)。”

'; } 返回$员额; }
在使用

$date = get_field('date', false, false);
您可以从该日期创建一个新的php DateTime对象

$date = new DateTime($date);
然后使用本机php格式函数

$date->format('M j, Y');

M选项自动为您提供月份首字母

我通过让ACF使用('M j,Y')给我一个自定义格式修复了它。

执行此操作后,我得到以下错误:类DateTime的对象无法转换为字符串编辑:解决了它,请参见上文,很高兴知道您已经探索了插件本身的可用选项:)