[wp-trac] [WordPress Trac] #28383: Adding have_the_post() as a shortcut to have_posts() and the_post() loops

WordPress Trac noreply at wordpress.org
Tue Jun 3 12:07:23 UTC 2014


#28383: Adding have_the_post() as a shortcut to have_posts() and the_post() loops
-------------------------+-----------------------
 Reporter:  sc0ttkclark  |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  4.0
Component:  Query        |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:  template
-------------------------+-----------------------

Comment (by kovshenin):

 > How many use cases are there really for using have_posts() without
 the_post()?

 In a while loop — none, because that would result in an infinite loop. In
 an if statement though, that's perfectly valid, because most often you
 don't want to advance the posts cursor until you actually hit the loop.

 I have mixed feelings about this, and although I do agree that "the loop"
 in its current form is a bit awkward, I don't see how `have_the_post()`
 makes it any easier, especially once you start working with secondary
 loops, where you need `wp_reset_postdata()`. It think it's already a bit
 too implicit with `the_post()` and moving that inside `have_the_post()`
 makes it even more implicit.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28383#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list