[wp-trac] [WordPress Trac] #20297: WP_Query implements IteratorAggregate
WordPress Trac
wp-trac at lists.automattic.com
Sun Mar 25 23:37:28 UTC 2012
#20297: WP_Query implements IteratorAggregate
-----------------------------+------------------------------
Reporter: hakre | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Resolution:
Keywords: has-patch close |
-----------------------------+------------------------------
Changes (by nacin):
* keywords: has-patch => has-patch close
Comment:
In theory, I really like #20296 and #20297. They could significantly
simplify how a loop looks. Instead of $query->have_posts() :
$query->the_post(), it could be foreach ( $query as $post ). Perhaps when
combined with WP_Post, they could be very powerful.
A few practical issues, however. For the main loop, you'd need to use
foreach( $wp_query ) -- directly accessing a global is worse than the
template tags we have now -- unless of course we introduced a wp_query()
function. Also, without WP_Post (which we definitely don't have), it's not
that helpful, especially if it doesn't call the_post() automatically on
iteration. Also, if it doesn't implement Countable (which it can't as SPL
can be disabled before 5.3), it would only be confusing for it to
implement IteratorAggregate.
I like the idea. I just don't think we're at the point yet where we should
do this. Especially since it is just as easy, for now, to run foreach()
and count() on $wp_query->posts. I suggest closing it as maybelater.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/20297#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list