Skip to content

Instantly share code, notes, and snippets.

@Balamir
Created June 15, 2016 10:20
Show Gist options
  • Select an option

  • Save Balamir/2b968112b5bd0d9a26743ceb76fdcaef to your computer and use it in GitHub Desktop.

Select an option

Save Balamir/2b968112b5bd0d9a26743ceb76fdcaef to your computer and use it in GitHub Desktop.
Wordpress - Search Query
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : ((get_query_var('page')) ? get_query_var('page') : 1);
$search = array(
'post_type' => 'properties',
'post_status' => 'publish',
'orderby' => $date_order,
'order' => $order,
'pagination' => true,
'posts_per_page' => 10,
'paged' => $paged,
'meta_query' => array(
'relation' => 'AND',
array(
array(
'key' => $sale_rent,
'meta_value' => array($min_price, $max_price),
'compare' => 'BETWEEN',
),
),
array(
array(
'key' => 'square_footage',
'meta_value' => $min_sqft,
'compare' => '>=',
),
array(
'key' => 'square_footage',
'meta_value' => $max_sqft,
'compare' => '<=',
),
),
),
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'prop-type',
'field' => 'slug',
'terms' => $property_type,
),
array(
'taxonomy' => 'prop-neighborhoods',
'field' => 'slug',
'terms' => $neighborhood,
)
),
);
$properties = new WP_Query($search);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment