Advertisement
chasecmiller

Show terms with matching descriptions.

Mar 30th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. // Paste into your search page.
  2.  
  3. if (array_key_exists('s', $_REQUEST) && $_REQUEST['s']) {
  4.     global $wpdb;
  5.     $s = array_map(function($e) { return esc_sql($e); },
  6.         explode(' ', urldecode($_REQUEST['s']))
  7.     );
  8.     $s = '(description LIKE "%'.implode('%" OR description LIKE "%', $s).'%")';
  9.     $res = $wpdb->get_results(sprintf('SELECT * FROM %s a INNER JOIN %s b ON b.term_id = a.term_id
  10. WHERE %s GROUP BY a.term_id',
  11.         $wpdb->term_taxonomy,
  12.         $wpdb->terms,
  13.         $s
  14.     ));
  15.    
  16.     if ($res) {
  17.         echo '<pre>'.var_export($res,true).'</pre>';
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement