'Date Format PHP WordPress Loop
I need to format the date output in the following WordPress PHP loop.
The current output looks like this: 2019-07-10 12:00:00
I would like it to look like this: July, 10th, 2019 (time not needed)
<?php
$event_query = new WP_Query(
array(
'post_type' => 'tribe_events',
'order' => 'asc',
'posts_per_page' => 2,
) //end array
); ?>
<?php while ($event_query->have_posts()) : $event_query->the_post(); ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php
$meta_print_value=get_post_meta(get_the_ID(),'_EventStartDate',true);
echo($meta_print_value);
?>
<?php the_excerpt(); ?>
<?php the_permalink(); ?>">View Event</a>
<?php endwhile; wp_reset_query(); ?>
I've tried several techniques, but can't get the PHP just right.
Solution 1:[1]
You can format a date with PHP's built in date function, see the documentation for all possibilities.
Here is what you'd like to achieve:
date('F, jS, Y', strtotime($wp_date));
Fiddle:
Solution 2:[2]
After $meta_print_value use below shared code:
$meta_val=date('F,S,Y',strtotime($meta_print_value));
Also replace echo($meta_print_value); into echo $meta_val;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andrew |
| Solution 2 | Dharman |
