To directly answer your question, you can use the wp_setup_nav_menu_item
filter to change properties of the nav menu item:
add_filter( 'wp_setup_nav_menu_item', static function ( $menu_item ) {
if ( ! is_admin() || empty( $menu_item->taxonomy ) || 'category' !== $menu_item->taxonomy ) {
return $menu_item;
}
$menu_item->title .= sprintf( ' (%s)', $menu_item->slug );
return $menu_item;
} );
The above approach may have unintended consequences, and pollutes the list of terms. A cleaner approach would be to intercept the AJAX call and implement your own search logic:
add_action( 'wp_ajax_menu-quick-search', static function () {
if ( ! current_user_can( 'edit_theme_options' ) ) {
wp_die( -1 );
}
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
$request = $_POST;
$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 ( ! preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches ) ) {
_wp_ajax_menu_quick_search( $_POST );
wp_die();
}
if ( 'taxonomy' !== $matches[1] ) {
_wp_ajax_menu_quick_search( $_POST );
wp_die();
}
// First, let's try to match our query with term's slug.
$terms = get_terms(
array(
'taxonomy' => $matches[2],
'search' => $query,
'number' => 10,
'hide_empty' => false,
)
);
// First search failed. Default to core logic: search by name.
if ( empty( $terms ) || is_wp_error( $terms ) ) {
$terms = get_terms(
array(
'taxonomy' => $matches[2],
'name__like' => $query,
'number' => 10,
'hide_empty' => false,
)
);
}
if ( empty( $terms ) || is_wp_error( $terms ) ) {
wp_die();
}
foreach ( (array) $terms as $term ) {
if ( 'markup' === $response_format ) {
echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args );
} elseif ( 'json' === $response_format ) {
echo wp_json_encode(
array(
'ID' => $term->term_id,
'post_title' => $term->name,
'post_type' => $matches[2],
)
);
echo "\n";
}
}
wp_die();
}, 0 );
For this approach, it copies a lot of code from WP core, so there may be incompatibilities in future versions.