I’m modifying the Recent-Changes WordPress plugin to display dates. I can echo the date but can’t format it; e.g., mm/dd/yyyy.
I’d like the post_modified date to be in mm/dd/yyyy.
I’ve tried–
echo '<li>'.$RecentChange->post_modified('m/d/Y').
— but that caused the plugin to stop displaying posts, and generally broke the site.
Below is the relevant chunk from the plugin–
/* define full SQL request */
$rc_sql = "SELECT post_date, post_modified, post_title, ID FROM wp_posts WHERE ".$rc_content_sql." ORDER BY post_modified DESC LIMIT ".$rc_number;
global $wpdb;
echo $before_widget;
echo $before_title.$rc_title.$after_title.'<ul>';
$RecentChanges = $wpdb->get_results($rc_sql);
if ($RecentChanges)
foreach ($RecentChanges as $RecentChange) :
$rc_url = get_page_link($RecentChange->ID);
echo '<li>'.$RecentChange->post_modified.' <a href='.$rc_url.'>'.$RecentChange->post_title.'</a></li>';
endforeach;
echo '</ul>'.$after_widget;
$wpdb->flush();
}
Try
See reference.
Assuming RecentChanges->post_modified is a PHP date or time, you could wrap it in PHP’s date function and format it how you want.
So, your line would look like this:
It’s likely that your code is breaking WordPress because the post_modified function is just a getter and doesn’t take parameters.