[wp-hackers] Resetting after multiple loops

Otto otto at ottodestruct.com
Sat Oct 25 13:25:16 GMT 2008


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
>> > }


More information about the wp-hackers mailing list