wp_ajax_ajax_tag_search

Ajax handler for tag search.

Description

wp_ajax_ajax_tag_search(); 

Usage

  1. if ( !function_exists( 'wp_ajax_ajax_tag_search' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ajax-actions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_ajax_ajax_tag_search(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_ajax_tag_search() { 
  2. if ( ! isset( $_GET['tax'] ) ) { 
  3. wp_die( 0 ); 
  4.  
  5. $taxonomy = sanitize_key( $_GET['tax'] ); 
  6. $tax = get_taxonomy( $taxonomy ); 
  7. if ( ! $tax ) { 
  8. wp_die( 0 ); 
  9.  
  10. if ( ! current_user_can( $tax->cap->assign_terms ) ) { 
  11. wp_die( -1 ); 
  12.  
  13. $s = wp_unslash( $_GET['q'] ); 
  14.  
  15. $comma = _x( ', ', 'tag delimiter' ); 
  16. if ( ', ' !== $comma ) 
  17. $s = str_replace( $comma, ', ', $s ); 
  18. if ( false !== strpos( $s, ', ' ) ) { 
  19. $s = explode( ', ', $s ); 
  20. $s = $s[count( $s ) - 1]; 
  21. $s = trim( $s ); 
  22.  
  23. /** 
  24. * Filters the minimum number of characters required to fire a tag search via Ajax. 
  25. * @since 4.0.0 
  26. * @param int $characters The minimum number of characters required. Default 2. 
  27. * @param WP_Taxonomy $tax The taxonomy object. 
  28. * @param string $s The search term. 
  29. */ 
  30. $term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s ); 
  31.  
  32. /** 
  33. * Require $term_search_min_chars chars for matching (default: 2) 
  34. * ensure it's a non-negative, non-zero integer. 
  35. */ 
  36. if ( ( $term_search_min_chars == 0 ) || ( strlen( $s ) < $term_search_min_chars ) ) { 
  37. wp_die(); 
  38.  
  39. $results = get_terms( $taxonomy, array( 'name__like' => $s, 'fields' => 'names', 'hide_empty' => false ) ); 
  40.  
  41. echo join( $results, "\n" ); 
  42. wp_die();