wppaste
WordPress

_wp_ajax_menu_quick_search( array $request = array() )

Since
3.0.0
Source
wp-admin/includes/nav-menu.php:23
Prints the appropriate response to a menu quick search.

Parameters

$requestarrayoptional
The unsanitized request values.Default: array()

Uses · 14

Show all 14

Used by · 1

Source

function _wp_ajax_menu_quick_search( $request = array() ) {	$args            = array();	$type            = isset( $request['type'] ) ? $request['type'] : '';	$object_type     = isset( $request['object_type'] ) ? $request['object_type'] : '';	$query           = isset( $request['q'] ) ? $request['q'] : '';	$response_format = isset( $request['response-format'] ) ? $request['response-format'] : ''; 	if ( ! $response_format || ! in_array( $response_format, array( 'json', 'markup' ), true ) ) {		$response_format = 'json';	} 	if ( 'markup' === $response_format ) {		$args['walker'] = new Walker_Nav_Menu_Checklist();	} 	if ( 'get-post-item' === $type ) {		if ( post_type_exists( $object_type ) ) {			if ( isset( $request['ID'] ) ) {				$object_id = (int) $request['ID']; 				if ( 'markup' === $response_format ) {					echo walk_nav_menu_tree(						array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ),						0,						(object) $args					);				} elseif ( 'json' === $response_format ) {					echo wp_json_encode(						array(							'ID'         => $object_id,							'post_title' => get_the_title( $object_id ),							'post_type'  => get_post_type( $object_id ),						)					);					echo "\n";				}			}		} elseif ( taxonomy_exists( $object_type ) ) {			if ( isset( $request['ID'] ) ) {				$object_id = (int) $request['ID']; 				if ( 'markup' === $response_format ) {					echo walk_nav_menu_tree(						array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ),						0,						(object) $args					);				} elseif ( 'json' === $response_format ) {					$post_obj = get_term( $object_id, $object_type );					echo wp_json_encode(						array(							'ID'         => $object_id,							'post_title' => $post_obj->name,							'post_type'  => $object_type,						)					);					echo "\n";				}			}		}	} elseif ( preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches ) ) {		if ( 'posttype' === $matches[1] && get_post_type_object( $matches[2] ) ) {			$post_type_obj = _wp_nav_menu_meta_box_object( get_post_type_object( $matches[2] ) );			$args          = array_merge(				$args,				array(					'no_found_rows'          => true,					'update_post_meta_cache' => false,					'update_post_term_cache' => false,					'posts_per_page'         => 10,					'post_type'              => $matches[2],					's'                      => $query,				)			); 			if ( isset( $post_type_obj->_default_query ) ) {				$args = array_merge( $args, (array) $post_type_obj->_default_query );			} 			$search_results_query = new WP_Query( $args );

History

Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-admin/includes/nav-menu.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.