Change how dates are formatted in custom fields in WordPress
P粉180844619
P粉180844619 2023-09-07 21:44:43
0
1
660

I created a custom field 'Event date' for my custom post type 'Event'. I'm trying to display a date on the front end and want to change the display format of the date but it doesn't seem to work. Here is the code 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!

P粉180844619
P粉180844619

reply all(1)
P粉187677012

Look, I answered my own question! WoohoooO!

<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>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template