Wrong date in recent posts
-
I’m new at WordPress. I had to fix a bug in a wordpress site where the recent date posts show the wrong date. The site is using the default WordPress widget to show the latest posts and their date in a sidebar column. The date showed is not the date of their posts but the date of the article page.
I don’t know if this is a mistake of the site developer (I’m not the site developer) or a plugin bug, forgive me if this bug is not related to ceceppa plugin.
In /wp-includes/widgets/class-wp-widget-recent-posts.php the post is showed here:
<li> <a href="<?php the_permalink( $recent_post->ID ); ?>"><?php echo $title ; ?></a> <?php if ( $show_date ) : ?> <span class="post-date"><?php echo get_the_date( '', $recent_post->ID ); ?></span> <?php endif; ?> </li>
In /wp-content/plugins/ceceppa-multilingua/frontend/frontend.php get_the_date is defined in this way:
function get_the_date( $the_date, $d ) { global $post; $format = CMLLanguage::get_current()->cml_date_format; if( empty( $format ) ) { $format = CMLUtils::get_date_format(); } else { if( ! empty( $d ) ) $format = $d; else $format = CMLUtils::get_date_format(); } $the_date = mysql2date( $format, $post->post_date ); return $the_date; }
As you can see, get_the_date shows the post_date of global $post and not $recent_post post_date.
I replaced in class-wp-widget-recent-posts.php this line:
<span class="post-date"><?php echo get_the_date( '', $recent_post->ID ); ?></span>
With this one:
<span class="post-date"><?php $tmppost = $GLOBALS['post']->post_date; $GLOBALS['post']->post_date = $recent_post->post_date; echo get_the_date( '', $recent_post->ID ); $GLOBALS['post']->post_date = $tmppost; unset($tmppost); ?></span>
And this ugly workaround fixed the bug.
The page I need help with: [log in to see the link]
- The topic ‘Wrong date in recent posts’ is closed to new replies.