I am using this function to display the date and title of my latest posts on my dashboard.
However for some of the posts the date is not being displayed at all – I have a feeling this might be the posts which I subsequently hit the “update” button but i am not sure.. any ideas why this happens?
function wps_recent_posts_dw() {
?>
<ol>
<?php
global $post;
$args = array( 'numberposts' => 10, 'post_type' => 'any' );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li> (<? the_date('j M, Y @ G:i'); ?>) <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ol>
<?php
}
function add_wps_recent_posts_dw() {
wp_add_dashboard_widget( 'wps_recent_posts_dw', __( 'Recent Posts' ), 'wps_recent_posts_dw' );
}
add_action('wp_dashboard_setup', 'add_wps_recent_posts_dw' );
Replace the_date() with the_time() and it should work fine.
the_date() only displays the date for posts that are on different days. If two posts are published on the same day, only the first one’s date will be displayed.
As the codex for the_date states:
So use the_time or get_the_date instead.