[wp-hackers] wp-hackers Digest, Vol 63, Issue 43

Jean-Patrick Smith chicagowebdev at gmail.com
Tue Apr 20 00:12:31 UTC 2010

> I could have a WP_Posts which extends the WP_Query object. I could say
> $posts = new WP_Posts() to get the default query. WP_Posts could
> implement Iterator (or IteratorAggregate), so then I could say
> something like
> foreach ($posts as $post) {
> $post->the_title();
> $post->the_content();
> }
> No globals, no fuss, no muss.
> Now, this sort of thing is PHP 5 only. Still, if the implementation is
> good, it might be the pushover point, eh?
> -Otto

This is pretty much what I'm doing currently.

Before I used to:
global $post;
$slideshow_images = get_posts($args);
$tmp = $post;
foreach($slideshow_images as $post)
   /* do stuff */
$post = $tmp;

It felt too hackish, the above is from memory so might be wrong but most
know the trick.

There could def. be some really good design issues addressed if Wordpress
was PHP5.2x+

I think just using the WP_Query object would suffice, and get_posts and
query_posts could be noted as not recommended, or explain clearly in the
beginning of the documentation how it'll screw up your site potentially (if
it doesn't already).

With any system though, it takes time to get used too and learn what the
best practices are. With WP it sort of seems like there are so many ways to
do it OK, and a few do it really well, but there's also design flaws in the
core mostly IMO because of PHP4 itself, I'm so used to OOP nowadays.

More information about the wp-hackers mailing list