[wp-trac] [WordPress Trac] #21110: Post Dates in wp_get_recent_posts list
WordPress Trac
wp-trac at lists.automattic.com
Fri Jun 29 08:53:38 UTC 2012
#21110: Post Dates in wp_get_recent_posts list
--------------------------+------------------------------
Reporter: oqm4 | Owner: oqm4
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 3.4
Severity: normal | Resolution:
Keywords: close |
--------------------------+------------------------------
Changes (by SergeyBiryukov):
* keywords: dev-feedback needs-codex => close
Comment:
This code works the same way for me on both 3.3.2 and 3.4.1.
As stated in Codex, `get_the_date()` relies on `$post` global, which this
code doesn't set. This results in the date of the first or the last post
in the main (or some other) loop being displayed, depending on where the
code is called from.
Setting `$post` inside the `foreach()` loop makes it work as expected:
{{{
$args = array( 'numberposts' => '3', 'post_status' => 'publish' );
$recent_posts = wp_get_recent_posts( $args );
global $post;
foreach( $recent_posts as $recent ){
$post = (object) $recent;
echo '<li id="date"><a href="' . get_permalink($recent["ID"]) . '"
title="'.esc_attr($recent["post_title"]).'" >' . get_the_date('M d') .
'</a></li><li><a href="' . get_permalink($recent["ID"]) . '"
title="'.esc_attr($recent["post_title"]).'" >' .
$recent["post_title"].'</a> -
'.esc_attr($recent["post_excerpt"]).'</li><li id="breaker"></li>';
}
wp_reset_postdata();
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21110#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list