[wp-hackers] strange get_posts behaviour in 2.1.1

Otto 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
use them.

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  [0], 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>"
> endforeach;
> 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.
> [0]     http://trac.wordpress.org/ticket/4251
> Paolo
> ------------------------------------
> Pixline Coding Collective
> http://pixline.net
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list