[wp-hackers] strange get_posts behaviour in 2.1.1
otto at ottodestruct.com
Thu Jul 26 20:25:25 GMT 2007
No, it's just that your code is wrong.
You're getting the posts into the $news array, and then you're
foreach'ing through them, setting each one to $post. What you're
missing is that just having the post inside $post doesn't make all the
template tags like get_permalink and the_title and such automagically
Add a call to setup_postdata($post) at the beginning of the foreach
loop. This will setup all the template tags correctly.
On 7/26/07, Pixline <supporto at pixline.net> wrote:
> maybe its just fault of another bug , but I can't understand why
> my widget returns a list of the same post, insteand of the latest n
> posts, here:
> $news = get_posts("numberposts=".$howmany);
> foreach($news as $post):
> echo "<li><a href='".get_permalink()."'>".the_title('','',false)."</
> a> <small>(".get_the_time('d/m',false).")</small>"
> it works on svn, but don't work in 2.2.1; I'm trying also other
> versions, but I really can't understand *why*. I also used all kinds
> of setup_postdata or similar to 'refresh' posts informations, but it
> simply don't work.
>  http://trac.wordpress.org/ticket/4251
> Pixline Coding Collective
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers