Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.31 KB | None | 0 0
  1. <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access pages directly.
  2. /**
  3.  * The template for displaying search room form.
  4.  *
  5.  * This template can be overridden by copying it to yourtheme/real-estate-x/search/results.php.
  6.  *
  7.  * @author  themebubble
  8.  * @version 1.0.0
  9.  */
  10.  
  11. $search_values = array();
  12. $tax_query     = array();
  13. $taxonomies = array(
  14.   'beds'          => 'Beds',
  15.   'baths'         => 'baths',
  16.   'property_type' => 'Property Type',
  17.   'city'          => 'City'
  18. );
  19.  
  20.  
  21. foreach($taxonomies as $key => $value) {
  22.   $var_name = 'idb_'.$value;
  23.   $search_values[$key] = idb_get_request($var_name);
  24. }
  25.  
  26.  
  27.  
  28.  
  29. $search_values['post_type'] = 'idb_listing';
  30. $search_values['paged'] = 1;
  31. $search_values['showposts'] = 4;
  32.  
  33. add_action( 'pre_get_posts', 'idb_modify_sql_query');
  34. function idb_modify_sql_query($query) {
  35.   if($title = $query->get('_meta_or_title')) {
  36.     add_filter( 'get_meta_sql', function($sql) use ($title) {
  37.       global $wpdb;
  38.       static $i = 0;
  39.       if(0 != $i++) return $sql;
  40.       $sql['where'] = sprintf(
  41.           " AND ( %s OR %s ) ",
  42.           $wpdb->prepare("{$wpdb->posts}.post_title like '%%%s%%'", $title),
  43.           $wpdb->prepare("{$wpdb->posts}.post_content like '%%%s%%'", $title),
  44.           mb_substr( $sql['where'], 5, mb_strlen( $sql['where'] ) )
  45.       );
  46.       return $sql;
  47.     });
  48.   }
  49. }
  50.  
  51. $idb_keyword = idb_get_request('idb_keyword');
  52. $search_values['_meta_or_title'] = $idb_keyword;
  53.  
  54. $search_values['meta_query'] = array(
  55.   array(
  56.     'meta_key' => 'keywords',
  57.     'value'    => $idb_keyword,
  58.     'compare'  => 'LIKE'
  59.   )
  60. );
  61.  
  62.  
  63. $idb_price_from = idb_get_request('idb_price_from');
  64. $idb_price_to   = idb_get_request('idb_price_to');
  65.  
  66. //global $post;
  67. //$meta_value = get_post_meta($post->ID, '_idb_listing_options', true);
  68. //var_dump($meta_value);
  69. $search_values['meta_query'] = array(
  70.   array(
  71.       'key'     => '_idb_price',
  72.       'value'   => array(200, 800),
  73.       'type'    => 'NUMERIC',
  74.       'compare' => 'BETWEEN'
  75.   ),
  76. );  
  77.  
  78. //global $post;
  79.  
  80. //global $wp_query;
  81.  
  82. //$existing_query = $wp_query;
  83.  
  84. $the_query = new WP_Query($search_values);
  85. if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
  86.  
  87.   the_title();
  88.   endwhile;
  89. endif;
  90.  
  91. //wp_reset_query();
  92. wp_reset_postdata();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement