Skip to main content
deleted 1 character in body
Source Link
Stephen Harris
  • 32.6k
  • 6
  • 84
  • 118

get_the_date must be used inside the Loop. For outside the loop use get_the_timeget_the_time.

$posts = get_posts(array('numberposts'=>-1)); //Get all published posts
foreach ($posts as $post){
    echo get_the_time('Y-m-d', $post->ID); //Echos date in Y-m-d format.
}

Consider replacing 'Y-m-d' in this example with get_option('date_format') as this will display the date as per your date format setting in wp-admin.

get_the_date must be used inside the Loop. For outside the loop use get_the_time.

$posts = get_posts(array('numberposts'=>-1)); //Get all published posts
foreach ($posts as $post){
    echo get_the_time('Y-m-d', $post->ID); //Echos date in Y-m-d format.
}

Consider replacing 'Y-m-d' in this example with get_option('date_format') as this will display the date as per your date format setting in wp-admin.

get_the_date must be used inside the Loop. For outside the loop use get_the_time.

$posts = get_posts(array('numberposts'=>-1)); //Get all published posts
foreach ($posts as $post){
    echo get_the_time('Y-m-d', $post->ID); //Echos date in Y-m-d format.
}

Consider replacing 'Y-m-d' in this example with get_option('date_format') as this will display the date as per your date format setting in wp-admin.

Suggest people use the global setting rather than hard coding the date format into the template
Source Link

get_the_date must be used inside the Loop. For outside the loop use get_the_time.

$posts = get_posts(array('numberposts'=>-1)); //Get all published posts
foreach ($posts as $post){
    echo get_the_time('Y-m-d', $post->ID); //Echos date in Y-m-d format.
}

Consider replacing 'Y-m-d' in this example with get_option('date_format') as this will display the date as per your date format setting in wp-admin.

get_the_date must be used inside the Loop. For outside the loop use get_the_time.

$posts = get_posts(array('numberposts'=>-1)); //Get all published posts
foreach ($posts as $post){
    echo get_the_time('Y-m-d', $post->ID); //Echos date in Y-m-d format.
}

get_the_date must be used inside the Loop. For outside the loop use get_the_time.

$posts = get_posts(array('numberposts'=>-1)); //Get all published posts
foreach ($posts as $post){
    echo get_the_time('Y-m-d', $post->ID); //Echos date in Y-m-d format.
}

Consider replacing 'Y-m-d' in this example with get_option('date_format') as this will display the date as per your date format setting in wp-admin.

added 203 characters in body
Source Link
Stephen Harris
  • 32.6k
  • 6
  • 84
  • 118

get_the_date must be used inside the Loop. For outside the loop use get_the_time.

$posts = get_posts(array('numberposts'=>-1)); //Get all published posts
foreach ($posts as $post){
    echo get_the_time('Y-m-d', $post->ID); //Echos date in Y-m-d format.
}

get_the_date must be used inside the Loop. For outside the loop use get_the_time.

get_the_date must be used inside the Loop. For outside the loop use get_the_time.

$posts = get_posts(array('numberposts'=>-1)); //Get all published posts
foreach ($posts as $post){
    echo get_the_time('Y-m-d', $post->ID); //Echos date in Y-m-d format.
}
Source Link
Stephen Harris
  • 32.6k
  • 6
  • 84
  • 118
Loading