英文:
Change custom field date formating WordPress
问题
我已经为我的自定义文章类型“Event”创建了一个自定义字段“事件日期”。我尝试在前端显示日期,并且想要更改日期显示的格式,但似乎无法工作。这是我尝试过的代码:
<div class="single-post-event-meta">
<p><?php
$event_date = get_post_meta(get_the_ID(), '_event_post_date_value_key');
echo $event_date[0]->format('M');
?></p>
</div>
谢谢帮助!
英文:
I have made a custom field 'Event date' for my custom post type 'Event'. I'm trying to display the date on the front-end and I want to change the format of how the date is displayed, but it doesn't seem to work. Here's what I tried:
<div class="single-post-event-meta">
<p><?php
$event_date = get_post_meta(get_the_ID(), '_event_post_date_value_key');
echo $event_date[0]->format('M');
?></p>
</div>
Thanks for the help!
答案1
得分: 0
看,我回答了自己的问题,哇喔喔!
<p class="single-post-event-meta-date"><?php
echo '日期:';
echo (new DateTime(get_post_meta($post>ID,'_event_post_date_value_key',true)))->format('d M Y');
?></p>
英文:
Look I answered my own question WoohoooO!
<p class="single-post-event-meta-date"><?php
echo 'Date: ';
echo (new DateTime(get_post_meta($post>ID,'_event_post_date_value_key',true)))->format('d M Y');
?></p>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论