Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I format the post date in Wordpress?

Tags:

I have a sidebar where I want to show the most recent posts. Right now it shows the title, date, and an excerpt. The date shows the time which I want to get rid of. I show the date using this: $recent["post_date"]

 <?php $args = array( 'numberposts' => '3' ); $recent_posts = wp_get_recent_posts( $args ); foreach( $recent_posts as $recent ){     echo '<li id="sidebar_text"><b>'.$recent["post_title"].'</b></li><li style="font-size:12px">'.$recent["post_date"].'</li><li><i style="font-size:15px">'.$recent["post_excerpt"].'</i><a href="'.get_permalink($recent["ID"]).'"> Read   More</a></li>';      }  ?> 

It shows the date like this: 2013-08-11 18:29:04 and I would like it like this 8-11-2013 and without the time. Thanks in advance.

like image 555
Mike Avatar asked Aug 11 '13 18:08

Mike


People also ask

How do I format the date in WordPress?

Using the the_time() and get_the_time() Functions You can use it to output the date by calling it as the_time('j F, Y') . The get_the_time() function works in a similar manner, but it returns the date instead of outputting it. This means that you will have to use echo get_the_time('j F, Y') to output the date.

How do I show the date on a WordPress post?

If you are building a Wordpress theme then there will a time when you want to display the date for the current post, luckily for you this is very easy with a Wordpress function the_date(). The the_date function will return the date of the post or the set of posts if published on the same date.

What do you mean by formatting date and time in WordPress?

What are Format Characters for Date and Time in WordPress? The date and time format are based alphabetic characters that represent a time format. For example, entering Y will output the year in numeric four digits, like 2014. Entering smaller case y will output the year in numeric two digits, like 14.


1 Answers

date('n-j-Y', strtotime($recent['post_date'])); 

This formats it the way you want. Just replace the $recent['post_date'] in your loop with that.

like image 176
ixchi Avatar answered Sep 25 '22 21:09

ixchi