Advertisement
Guest User

Untitled

a guest
Nov 21st, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. <!-- THE RESULTS -->
  2. <div id="Container">
  3. <!-- WARNING IF NO RESULTS -->
  4. <div class="alert alert-danger alert-dismissible fail-message" role=alert>
  5. <button type=button class=close data-dismiss=alert aria-label=Close><span aria-hidden=true>&times;</span></button>
  6. No items were found matching the current filters.
  7. </div>
  8.  
  9. <?php
  10. // todo - sanitise and validate
  11. $property_location = $_GET['property-location'] != '' ? $_GET['property-location'] : '';
  12. $bedrooms = $_GET['bedrooms'] != '' ? $_GET['bedrooms'] : '';
  13. $bathrooms = $_GET['bathrooms'] != '' ? $_GET['bathrooms'] : '';
  14.  
  15. $tax_query = array();
  16. if( !empty($property_location) ) {
  17. $tax_query[] = array(
  18. 'taxonomy' => 'property-location',
  19. 'field' => 'slug' ,
  20. 'terms' => $property_location
  21. );
  22. }
  23.  
  24. $meta_query = array();
  25. if( !empty($bedrooms) ) {
  26. $meta_query[] = array(
  27. 'key' => 'bedrooms',
  28. 'value' => $bedrooms ,
  29. 'compare' => '>='
  30. );
  31. }
  32. if( !empty($bathrooms) ) {
  33. $meta_query[] = array(
  34. 'key' => 'baths',
  35. 'value' => $bathrooms ,
  36. 'compare' => '>='
  37. );
  38. }
  39.  
  40. $args = array(
  41. 'post_type' => 'listing',
  42. 'posts_per_page' => -1,
  43. 'tax_query' => $tax_query,
  44. 'meta_query' => $meta_query,
  45. 'fields' => 'ids'
  46. );
  47.  
  48. $listingSearch = new WP_Query( $args );
  49. if ( $listingSearch->have_posts() ) {
  50. while ( $listingSearch->have_posts() ) {
  51. $listingSearch->the_post();
  52. get_template_part( 'loop', 'grid' );
  53. } // end while
  54. } // endif
  55. else {
  56. // else there are no posts/error
  57. // this is handled by the javascript
  58. }
  59. // END OF LOOP
  60.  
  61. ?>
  62. </div><!-- #Container -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement