[wp-hackers] Resetting after multiple loops
Otto
otto at ottodestruct.com
Sat Oct 25 14:30:22 GMT 2008
Harumph. Maybe I just like Object Oriented code more.
$myquery = new WP_Query('whatever');
while ($myquery->have_posts()) : $myquery->the_post();
the_title();
the_content();
endwhile;
On Sat, Oct 25, 2008 at 9:27 AM, Viper007Bond <viper at viper007bond.com> wrote:
> My code makes no assumptions. You can use $foobar instead of $post if you so
> wish. I mean you're gonna end up doing setup_postdata($foobar); probably
> anyway.
>
> On Sat, Oct 25, 2008 at 6:25 AM, Otto <otto at ottodestruct.com> wrote:
>
>> Even your example code makes the rather large assumption that you are
>> in the global variable context. Look at how you use $post. ;)
>>
>> My point is that no matter how you swing it, you tend to leave odd
>> side effects when messing with get_posts. Using a new WP_Posts doesn't
>> have those, generally speaking. Not unless you're using it wrong.
>>
>>
>> On Fri, Oct 24, 2008 at 9:31 PM, Viper007Bond <viper at viper007bond.com>
>> wrote:
>> > How so? It just returns an array that you can easily loop through. No
>> need
>> > to use have_posts(), the_post(), etc.
>> >
>> > On Fri, Oct 24, 2008 at 10:52 AM, Otto <otto at ottodestruct.com> wrote:
>> >
>> >> Creating a new WP_Query() seems like the better approach to me, as
>> >> that never touches the default query in any way.
>> >>
>> >> Whereas get_posts() can be confusing and difficult to use.
>> >>
>> >>
>> >>
>> >> On Fri, Oct 24, 2008 at 8:46 AM, Viper007Bond <viper at viper007bond.com>
>> >> wrote:
>> >> > Always use code like this if possible:
>> >> >
>> >> > $var_name_other_than_posts = get_posts( 'some=parameters' );
>> >> >
>> >> > foreach ( $var_name_other_than_posts as $post ) {
>> >> > // do stuff
>> >> > }
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>
>
>
> --
> Viper007Bond | http://www.viper007bond.com/ | http://www.finalgear.com/
> _______________________________________________
> 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