Advertisement
luisabarca

Custom search for floor plan

Dec 5th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1. <?php
  2. add_action('pre_get_posts', 'realty_dosearch');
  3.  
  4.  
  5. /**
  6.  *
  7.  * Ejecuta la busqueda de propiedades
  8.  */
  9. function realty_dosearch()
  10. {
  11.     global $wp_query;
  12.  
  13.     // just search when is post type floor plan
  14.     if ( $wp_query->query_vars['post_type'] != 'floor_plan' ) {
  15.         return false;
  16.     }
  17.  
  18.     // dont needed because you are sending the search to a custom post type page
  19.     //$wp_query->query_vars['post_type'] = 'floor_plan';
  20.  
  21.     $bedrooms = get_query_var('bedrooms');
  22.  
  23.     if (!empty($area) && $area > 0) {
  24.         $meta_query = array();
  25.  
  26.         $meta_query[] = array(
  27.             'key'     => 'number_of_bedrooms',
  28.             'value'   => $bedrooms,
  29.             'compare' => '=',
  30.             'type'    => 'NUMERIC'
  31.         );
  32.  
  33.         $wp_query->query_vars['meta_query'] = $meta_query;
  34.     }
  35. }
  36.  
  37. // }}}
  38. // {{{
  39.  
  40. add_filter('query_vars', 'realty_query_vars');
  41.  
  42. function realty_query_vars($query_vars)
  43. {
  44.     $query_vars[] = 'bedrooms';    
  45.     return $query_vars;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement