@@ -271,8 +271,8 @@ function wp_nav_menu_post_type_meta_boxes() {
271271 *
272272 * @since 3.0.0
273273 *
274- * @param WP_Post_Type|false $post_type The current object to add a menu items
275- * meta box for.
274+ * @param WP_Post_Type|WP_Taxonomy| false $post_type The current post type or taxonomy object
275+ * for the meta box .
276276 */
277277 $ post_type = apply_filters ( 'nav_menu_meta_box_object ' , $ post_type );
278278
@@ -864,11 +864,12 @@ function wp_nav_menu_item_taxonomy_meta_box( $data_object, $box ) {
864864 $ taxonomy_name = $ box ['args ' ]->name ;
865865 $ taxonomy = get_taxonomy ( $ taxonomy_name );
866866 $ tab_name = $ taxonomy_name . '-tab ' ;
867+ $ default_query = isset ( $ box ['args ' ]->_default_query ) ? (array ) $ box ['args ' ]->_default_query : array ();
867868
868869 // Paginate browsing for large numbers of objects.
869- $ per_page = 50 ;
870+ $ per_page = isset ( $ default_query [ ' number ' ] ) ? ( int ) $ default_query [ ' number ' ] : 50 ;
870871 $ pagenum = isset ( $ _REQUEST [ $ tab_name ] ) && isset ( $ _REQUEST ['paged ' ] ) ? absint ( $ _REQUEST ['paged ' ] ) : 1 ;
871- $ offset = 0 < $ pagenum ? $ per_page * ( $ pagenum - 1 ) : 0 ;
872+ $ offset = 0 < $ per_page && 0 < $ pagenum ? $ per_page * ( $ pagenum - 1 ) : 0 ;
872873
873874 $ args = array (
874875 'taxonomy ' => $ taxonomy_name ,
@@ -883,6 +884,12 @@ function wp_nav_menu_item_taxonomy_meta_box( $data_object, $box ) {
883884 'orderby ' => 'name ' ,
884885 'pad_counts ' => false ,
885886 );
887+ $ args = array_merge ( $ args , $ default_query );
888+
889+ // WP_Term_Query uses 0 to return all terms, unlike WP_Query's -1.
890+ if ( 0 > $ per_page ) {
891+ $ args ['number ' ] = 0 ;
892+ }
886893
887894 $ terms = get_terms ( $ args );
888895
@@ -891,17 +898,20 @@ function wp_nav_menu_item_taxonomy_meta_box( $data_object, $box ) {
891898 return ;
892899 }
893900
894- $ num_pages = (int ) ceil (
895- (int ) wp_count_terms (
896- array_merge (
897- $ args ,
898- array (
899- 'number ' => '' ,
900- 'offset ' => '' ,
901+ $ num_pages = 1 ;
902+ if ( 0 < $ per_page ) {
903+ $ num_pages = (int ) ceil (
904+ (int ) wp_count_terms (
905+ array_merge (
906+ $ args ,
907+ array (
908+ 'number ' => '' ,
909+ 'offset ' => '' ,
910+ )
901911 )
902- )
903- ) / $ per_page
904- );
912+ ) / $ per_page
913+ );
914+ }
905915
906916 $ page_links = paginate_links (
907917 array (
@@ -1218,32 +1228,38 @@ function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() ) {
12181228 */
12191229function _wp_nav_menu_meta_box_object ( $ data_object = null ) {
12201230 if ( isset ( $ data_object ->name ) ) {
1231+ $ default_query = array ();
12211232
12221233 if ( 'page ' === $ data_object ->name ) {
1223- $ data_object -> _default_query = array (
1234+ $ default_query = array (
12241235 'orderby ' => 'menu_order title ' ,
12251236 'post_status ' => 'publish ' ,
12261237 );
12271238
12281239 // Posts should show only published items.
12291240 } elseif ( 'post ' === $ data_object ->name ) {
1230- $ data_object -> _default_query = array (
1241+ $ default_query = array (
12311242 'post_status ' => 'publish ' ,
12321243 );
12331244
12341245 // Categories should be in reverse chronological order.
12351246 } elseif ( 'category ' === $ data_object ->name ) {
1236- $ data_object -> _default_query = array (
1247+ $ default_query = array (
12371248 'orderby ' => 'id ' ,
12381249 'order ' => 'DESC ' ,
12391250 );
12401251
12411252 // Custom post types should show only published items.
12421253 } else {
1243- $ data_object -> _default_query = array (
1254+ $ default_query = array (
12441255 'post_status ' => 'publish ' ,
12451256 );
12461257 }
1258+
1259+ $ data_object ->_default_query = array_merge (
1260+ $ default_query ,
1261+ (array ) ( $ data_object ->_default_query ?? array () )
1262+ );
12471263 }
12481264
12491265 return $ data_object ;
0 commit comments