um_add_search_to_query

The Ultimate Member um add search to query function.

Description

um_add_search_to_query( $query_args, $args ); 

Parameters (2)

0. $query_args
The query args.
1. $args
The args.

Usage

  1. if ( !function_exists( 'um_add_search_to_query' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ultimate-member/core/um-filters-members.php'; 
  3.  
  4. // The query args. 
  5. $query_args = null; 
  6.  
  7. // The args. 
  8. $args = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = um_add_search_to_query($query_args, $args); 
  12.  

Defined (1)

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

/core/um-filters-members.php  
  1. function um_add_search_to_query( $query_args, $args ) { 
  2. global $ultimatemember; 
  3. extract( $args ); 
  4.  
  5. if ( isset( $_REQUEST['um_search'] ) ) { 
  6.  
  7. $query = $ultimatemember->permalinks->get_query_array(); 
  8.  
  9. // if searching 
  10. if( isset( $query['search'] ) ) { 
  11. $query_args['search'] = '*' . um_filter_search( $query['search'] ) . '*'; 
  12. unset( $query['search'] ); 
  13.  
  14. if ( $query && is_array( $query ) ) { 
  15. foreach( $query as $field => $value ) { 
  16.  
  17. if(in_array($field, array('members_page'))) continue; 
  18.  
  19. $serialize_value = serialize( strval( $value ) ); 
  20.  
  21. if ( $value && $field != 'um_search' && $field != 'page_id' ) { 
  22.  
  23. if( strstr( $field, 'role_') ) { 
  24. $field = 'role'; 
  25.  
  26. if ( !in_array( $field, $ultimatemember->members->core_search_fields ) ) { 
  27.  
  28. $field_query = array( 
  29. array( 
  30. 'key' => $field,  
  31. 'value' => trim( $value ),  
  32. 'compare' => '=',  
  33. ),  
  34. array( 
  35. 'key' => $field,  
  36. 'value' => trim( $value ),  
  37. 'compare' => 'LIKE',  
  38. ),  
  39. array( 
  40. 'key' => $field,  
  41. 'value' => trim( $serialize_value ),  
  42. 'compare' => 'LIKE',  
  43. ),  
  44. 'relation' => 'OR',  
  45. ); 
  46.  
  47.  
  48. $field_query = apply_filters("um_query_args_{$field}__filter", $field_query ); 
  49. $query_args['meta_query'][] = $field_query; 
  50.  
  51.  
  52.  
  53.  
  54.  
  55. // allow filtering 
  56. $query_args = apply_filters('um_query_args_filter', $query_args ); 
  57.  
  58. if ( count ($query_args['meta_query']) == 1 ) { 
  59. unset( $query_args['meta_query'] ); 
  60.  
  61. return $query_args; 
  62.