Advertisement
Guest User

WP tax_query

a guest
Jun 21st, 2012
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. function advanced_product_search_filter($query)
  2. {
  3.   if(!is_admin() &&
  4.      is_main_query() &&
  5.      is_search() && $query->query_vars['post_type'] == 'product')
  6.   {
  7.     $keyword = $_GET['s'];
  8.  
  9.     if($_GET['exactly'])
  10.       $keyword = $_GET['s'] . ' "'. $_GET['exactly'] . '"';
  11.  
  12.     if($_GET['without'])
  13.     {
  14.       $excluded = exclude_product_keyword_search($_GET['without'],
  15.                     $_GET['pname'],
  16.                     $_GET['pcode']
  17.                   );
  18.       $query->set('post__not_in', $excluded);
  19.     }
  20.  
  21.     if($_GET['pname'])
  22.       $query->set('s', $keyword);
  23.     else
  24.       $query->set('s', '');
  25.  
  26.     if($_GET['pcode'])
  27.     {
  28.       $tax_queries = $query->get('tax_query');
  29.       $tax_queries[] = array(
  30.         array(
  31.           'taxonomy' => 'pa_ordering-code',
  32.           'field' => 'name',
  33.           'terms' => array($keyword),
  34.           'operator' => 'LIKE'
  35.         )
  36.       );
  37.       $query->set('tax_query', $tax_queries);
  38.     }
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement