diff --git src/wp-admin/js/customize-nav-menus.js src/wp-admin/js/customize-nav-menus.js
index b4e7be5..7b0ba4c 100644
|
|
|
115 | 115 | pages: {}, |
116 | 116 | sectionContent: '', |
117 | 117 | loading: false, |
| 118 | excludeTerms: [], |
118 | 119 | |
119 | 120 | initialize: function() { |
120 | 121 | var self = this; |
… |
… |
|
218 | 219 | } |
219 | 220 | |
220 | 221 | this.searchTerm = event.target.value; |
| 222 | this.excludeTerms = []; |
221 | 223 | this.pages.search = 1; |
222 | 224 | this.doSearch( 1 ); |
223 | 225 | }, |
… |
… |
|
251 | 253 | 'customize-menus-nonce': api.Menus.data.nonce, |
252 | 254 | 'wp_customize': 'on', |
253 | 255 | 'search': self.searchTerm, |
254 | | 'page': page |
| 256 | 'page': page, |
| 257 | 'exclude': _.filter( self.excludeTerms, function( value, index, list ) { |
| 258 | return list.indexOf( value ) === index; |
| 259 | } ) |
255 | 260 | }; |
256 | 261 | |
257 | 262 | self.currentRequest = wp.ajax.post( 'search-available-menu-items-customizer', params ); |
258 | 263 | |
259 | 264 | self.currentRequest.done(function( data ) { |
260 | | var items; |
| 265 | var items, lastItem, lastItemPosition; |
261 | 266 | if ( 1 === page ) { |
262 | 267 | // Clear previous results as it's a new search. |
263 | 268 | $content.empty(); |
… |
… |
|
270 | 275 | self.collection.add( items.models ); |
271 | 276 | items.each( function( menuItem ) { |
272 | 277 | $content.append( itemTemplate( menuItem.attributes ) ); |
| 278 | if ( 'taxonomy' === menuItem.attributes.type ) { |
| 279 | self.excludeTerms.push( menuItem.attributes.object_id ); |
| 280 | } |
273 | 281 | } ); |
274 | 282 | if ( 20 > items.length ) { |
275 | 283 | self.pages.search = -1; // Up to 20 posts and 20 terms in results, if <20, no more results for either. |
… |
… |
|
281 | 289 | } else if ( items && page === 1 ) { |
282 | 290 | wp.a11y.speak( api.Menus.data.l10n.itemsFound.replace( '%d', items.length ) ); |
283 | 291 | } |
| 292 | |
| 293 | lastItem = $content.find( 'li' ).last(); |
| 294 | lastItemPosition = lastItem.position().top + lastItem.outerHeight( true ); |
| 295 | |
| 296 | // The window is larger than the results. Initiate a scroll event to query page 2. |
| 297 | if ( -1 !== self.pages.search && 1 === page && $content.prop( 'scrollHeight' ) > lastItemPosition ) { |
| 298 | $content.scroll(); |
| 299 | } |
284 | 300 | }); |
285 | 301 | |
286 | 302 | self.currentRequest.fail(function( data ) { |
diff --git src/wp-includes/class-wp-customize-nav-menus.php src/wp-includes/class-wp-customize-nav-menus.php
index adccacd..e832275 100644
|
|
final class WP_Customize_Nav_Menus { |
208 | 208 | wp_send_json_error( 'nav_menus_missing_search_parameter' ); |
209 | 209 | } |
210 | 210 | |
| 211 | $e = ! empty( $_POST['exclude'] ) ? array_filter( $_POST['exclude'], 'absint' ) : array(); |
211 | 212 | $p = isset( $_POST['page'] ) ? absint( $_POST['page'] ) : 0; |
212 | 213 | if ( $p < 1 ) { |
213 | 214 | $p = 1; |
214 | 215 | } |
215 | 216 | |
216 | 217 | $s = sanitize_text_field( wp_unslash( $_POST['search'] ) ); |
217 | | $items = $this->search_available_items_query( array( 'pagenum' => $p, 's' => $s ) ); |
| 218 | $items = $this->search_available_items_query( array( 'exclude' => $e, 'pagenum' => $p, 's' => $s ) ); |
218 | 219 | |
219 | 220 | if ( empty( $items ) ) { |
220 | 221 | wp_send_json_error( array( 'message' => __( 'No results found.' ) ) ); |
… |
… |
final class WP_Customize_Nav_Menus { |
231 | 232 | * @since 4.3.0 |
232 | 233 | * @access public |
233 | 234 | * |
234 | | * @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments. |
| 235 | * @param array $args Optional. Accepts 'exclude' (term IDs), 'pagenum', and 's' (search) arguments. |
235 | 236 | * @return array Menu items. |
236 | 237 | */ |
237 | 238 | public function search_available_items_query( $args = array() ) { |
… |
… |
final class WP_Customize_Nav_Menus { |
254 | 255 | $query['s'] = $args['s']; |
255 | 256 | } |
256 | 257 | |
| 258 | if ( ! isset( $args['exclude'] ) ) { |
| 259 | $args['exclude'] = array(); |
| 260 | } |
| 261 | |
257 | 262 | // Query posts. |
258 | 263 | $get_posts = new WP_Query( $query ); |
259 | 264 | |
… |
… |
final class WP_Customize_Nav_Menus { |
282 | 287 | $terms = get_terms( $taxonomies, array( |
283 | 288 | 'name__like' => $args['s'], |
284 | 289 | 'number' => 20, |
285 | | 'offset' => 20 * ($args['pagenum'] - 1), |
| 290 | 'exclude' => $args['exclude'], |
286 | 291 | ) ); |
287 | 292 | |
288 | 293 | // Check if any taxonomies were found. |