[wp-trac] [WordPress Trac] #27042: Use of the_post() in _wp_admin_menu_quick_search() is making in_the_loop = true

WordPress Trac noreply at wordpress.org
Thu Feb 6 20:54:28 UTC 2014


#27042: Use of the_post() in _wp_admin_menu_quick_search() is making in_the_loop =
true
----------------------------+-----------------------------
 Reporter:  ruud@…          |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Menus           |    Version:  trunk
 Severity:  normal          |   Keywords:
  Focuses:  administration  |
----------------------------+-----------------------------
 In /wp-admin/includes/nav-menu.php the menu quick search results are
 transfered to a json response by doing a search and looping over the
 results with a 'regular' have_posts(): the_post() construction.
 As a side-effect the in_the_loop gets set to true in the_post() function.

 This being an admin facing display of (custom)posts titles, I didn't
 suspect this behavior.

 If this is indeed not meant to be, then I can think of 2 solutions:
 1) Quick (and dirty?) add an if ( is_admin() ) check to the_post(), to
 prevent accidental setting of 'in_the_loop' while in the admin.
 2) Don't use the_post() in _wp_admin_menu_quick_search().

 For the latter I did some looking around in the admin for other similar
 situations and cooked up the attached patch.

 While in this function I did some further code tidying.

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


More information about the wp-trac mailing list