[wp-trac] [WordPress Trac] #41508: wp_get_nav_menu_items() does not account for posts_per_page

WordPress Trac noreply at wordpress.org
Tue Aug 1 09:53:37 UTC 2017


#41508: wp_get_nav_menu_items() does not account for posts_per_page
--------------------------+-----------------------------
 Reporter:  Compute       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Menus         |    Version:  4.8
 Severity:  normal        |   Keywords:
  Focuses:  template      |
--------------------------+-----------------------------
 When passing $args['posts_per_page'] to wp_get_nav_menu_items $args, it
 returns the same amount of items as if the argument was left out.

 It seems like this is due to the following line:

 {{{
 $args['include'] = $items;
 }}}

 The get_posts argument is described as following:


 {{{
 'include'
         (array) An array of post IDs to retrieve, sticky posts will be
 included. Is an alias of $post__in in WP_Query. Default empty array.
 }}}

 But really it does the following:

 {{{
 if ( ! empty($r['include']) ) {
     $incposts = wp_parse_id_list( $r['include'] );
     $r['posts_per_page'] = count($incposts);  // only the number of posts
 included
     $r['post__in'] = $incposts;
 }
 }}}

 Meaning that if `include` is passed `posts_per_page` will get ignored.

 An alternative would be to use `post__in` instead of `include` in
 `wp_get_nav_menu_items()`:
 https://github.com/WordPress/WordPress/blob/36759db92ed78900a9d96c63b4e0ff0ae6313fe7
 /wp-includes/nav-menu.php#L625

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


More information about the wp-trac mailing list