_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()
Hooks fired · 1
One hook fires while _wp_ajax_menu_quick_search() runs, in this order:
- apply_filters( wp_ajax_menu_quick_search_args )filterline 112 (+89 into the body)
Filter the menu quick search arguments.
Uses · 15
- post_type_exists()Determines whether a post type is registered.
- walk_nav_menu_tree()Retrieves the HTML list content for nav menu items.
- get_post()Retrieves post data given a post ID or post object.
- wp_json_encode()Encodes a variable into JSON, with some confidence checks.
- get_the_title()Retrieves the post title.
- get_post_type()Retrieves the post type of the current post or of a given post.
- taxonomy_exists()Determines whether the taxonomy name exists.
- get_term()Gets all term data from database by term ID.
- get_post_type_object()Retrieves a post type object by name.
- _wp_nav_menu_meta_box_object()Adds custom arguments to some of the meta box object types.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_terms()Retrieves the terms in a given taxonomy or list of taxonomies.
Show all 15
- is_wp_error()Checks whether the given variable is a WordPress Error.
- Walker_Nav_Menu_Checklist::__construct()
- WP_Query::__construct()Constructor.
Used by · 1
- wp_ajax_menu_quick_search()Handles menu quick searching via AJAX.
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-Z0-9_-]*\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] ) ); $query_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, 'search_columns' => array( 'post_title' ), ); /** * Filter the menu quick search arguments. * * @since 6.9.0 * * @param array $args { * Menu quick search arguments. *History
Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.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.