Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access pages directly.
- /**
- * The template for displaying search room form.
- *
- * This template can be overridden by copying it to yourtheme/real-estate-x/search/results.php.
- *
- * @author themebubble
- * @version 1.0.0
- */
- $search_values = array();
- $tax_query = array();
- $taxonomies = array(
- 'beds' => 'Beds',
- 'baths' => 'baths',
- 'property_type' => 'Property Type',
- 'city' => 'City'
- );
- foreach($taxonomies as $key => $value) {
- $var_name = 'idb_'.$value;
- $search_values[$key] = idb_get_request($var_name);
- }
- $search_values['post_type'] = 'idb_listing';
- $search_values['paged'] = 1;
- $search_values['showposts'] = 4;
- add_action( 'pre_get_posts', 'idb_modify_sql_query');
- function idb_modify_sql_query($query) {
- if($title = $query->get('_meta_or_title')) {
- add_filter( 'get_meta_sql', function($sql) use ($title) {
- global $wpdb;
- static $i = 0;
- if(0 != $i++) return $sql;
- $sql['where'] = sprintf(
- " AND ( %s OR %s ) ",
- $wpdb->prepare("{$wpdb->posts}.post_title like '%%%s%%'", $title),
- $wpdb->prepare("{$wpdb->posts}.post_content like '%%%s%%'", $title),
- mb_substr( $sql['where'], 5, mb_strlen( $sql['where'] ) )
- );
- return $sql;
- });
- }
- }
- $idb_keyword = idb_get_request('idb_keyword');
- $search_values['_meta_or_title'] = $idb_keyword;
- $search_values['meta_query'] = array(
- array(
- 'meta_key' => 'keywords',
- 'value' => $idb_keyword,
- 'compare' => 'LIKE'
- )
- );
- $idb_price_from = idb_get_request('idb_price_from');
- $idb_price_to = idb_get_request('idb_price_to');
- //global $post;
- //$meta_value = get_post_meta($post->ID, '_idb_listing_options', true);
- //var_dump($meta_value);
- $search_values['meta_query'] = array(
- array(
- 'key' => '_idb_price',
- 'value' => array(200, 800),
- 'type' => 'NUMERIC',
- 'compare' => 'BETWEEN'
- ),
- );
- //global $post;
- //global $wp_query;
- //$existing_query = $wp_query;
- $the_query = new WP_Query($search_values);
- if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
- the_title();
- endwhile;
- endif;
- //wp_reset_query();
- wp_reset_postdata();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement