Dynamic Web Lab
Back to insights

get post publish date outside the loop in wordpress

February 17, 20131 min read

To get post publish date outside the loop in wordpress use the following code.

[php]
$all_posts = get_posts(array(‘numberposts’=>-1, ‘post_status’=> ‘publish’)); //Get all published posts
foreach ($all_posts as $single_post){
echo get_the_time(‘Y-m-d’, $single_post->ID); //The date is on Y-m-d format
echo ‘<br />’ ;
}
[/php]

Hope this code will help you.
Thanks

Writer

Dynamic Web Lab Editorial

We share how we design, engineer, and scale digital products across the GCC, Europe, and the US.

Share this article

Tags

PHPwordpress

Need help implementing this?

We turn these playbooks into shipped features. Let us scope your roadmap and support your team.

Start a project conversation