Guest User

Untitled

a guest
Oct 1st, 2015
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function hsta_search_posts_join($joins) {
  2.   global $wpdb;
  3.   return $joins . " INNER JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)";
  4. }
  5.  
  6. function hsta_search_posts_join($search,$qry) {
  7.   global $wpdb;
  8.   $add = $wpdb->prepare("({$wpdb->postmeta}.meta_key = 'pt_assessment' AND CAST({$wpdb->postmeta}.meta_value AS CHAR) LIKE '%%%s%%')",$qry->get('s'));
  9.   $pat = '|\(\((.+)\)\)|';
  10.   $search = preg_replace($pat,'(($1 OR '.$add.'))',$search);
  11.   return $search;
  12. }
  13.  
  14. $args['s'] = $_REQUEST['search'];
  15. $args = array(
  16.   'post_type' => array( 'news_article', 'perf_task', 'lesson_plan', 'diff_perf_task', 'diff_lesson_plan' ),
  17.   's' => $args['s']
  18. );
  19.  
  20. function update_results(){
  21.  
  22. add_filter('posts_join','hsta_search_posts_join');
  23. add_filter('posts_search','hsta_search_posts_join',1,2);
  24.  
  25. $custom_q = new WP_Query($args);
  26.  
  27. // tests
  28. //var_dump($custom_q->request);
  29. //var_dump($custom_q->posts);
  30.  
  31. wp_send_json_success($custom_q->posts);
  32.  
  33. remove_filter('posts_join','hsta_search_posts_join');
  34. remove_filter('posts_search','hsta_search_posts_join',1,2);
  35.  
  36. }
  37.  
  38. add_action( 'wp_ajax_update_results', 'update_results' );
  39. add_action( 'wp_ajax_nopriv_update_results', 'update_results' );
RAW Paste Data