[wp-trac] [WordPress Trac] #39483: Use $wp_the_query for the main loop and pagination

WordPress Trac noreply at wordpress.org
Thu Jan 5 13:58:22 UTC 2017


#39483: Use $wp_the_query for the main loop and pagination
-------------------------+-----------------------------
 Reporter:  prosti       |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Query        |    Version:
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 `query_posts()` hasn't been deprecated. And it should not.
 http://wordpress.stackexchange.com/questions/226960/why-query-posts-isnt-
 marked-as-deprecated

 Nothing bad with that function.

 However, we may improve things further.

 The main query will set both the globals `$wp_the_query` and `$wp_query`.

 [[Image(https://i.stack.imgur.com/nsaZ5.png)]]

 The loop =


 {{{
 while ( have_posts() ) : the_post();
 ...
 endwhile;
 }}}


 and pagination that works via  `paginate_links()`

 are both // dependent on `$wp_query` or `=f($wp_query)`


 However, the frozen variable is `$wp_the_query`.

 This is why I suggest the while loop needs to be organized to depend on
 `$wp_the_query` instead. The very same should be the case for the
 pagination function `paginate_links()`.

 ----


 This way we may use `query_posts` even without the need to run
 `wp_reset_query()`, since `query_posts` breaks these two variables (
 `$wp_query` and `$wp_the_query` ) being equal.

 [[Image(https://i.stack.imgur.com/RWSbJ.png)]]

 ----

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39483>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list