Guest User

Untitled

a guest
Jan 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. <?php
  2.  
  3. // Set up default query
  4. $locations_query_args = [
  5. 'post_type' => 'locations',
  6. 'post_status' => 'publish',
  7. 'posts_per_page' => 500,
  8. ];
  9.  
  10. // Add the search query if set ($town_city_selected)
  11. if ( false !== $town_city_selected ) {
  12. $locations_query_args['s'] = esc_attr( $town_city_selected );
  13. }
  14.  
  15. // Set the nearest station if set
  16. if ( false !== $nearest_station_selected ) {
  17. $locations_query_args['tax_query'][] = [
  18. 'taxonomy' => 'nearest_station',
  19. 'field' => 'term_id',
  20. 'terms' => esc_attr( $nearest_station_selected ),
  21. ];
  22. }
  23.  
  24. // Set the theme(s) if set
  25. if ( false !== $themes_selected ) {
  26. $locations_query_args['tax_query'][] = [
  27. 'taxonomy' => 'themes',
  28. 'field' => 'term_id',
  29. 'terms' => $themes_selected,
  30. ];
  31. }
  32.  
  33. // If BOTH taxonomies (nearest station and theme(s)) have a value then this is a relation = AND query (we need to deal with both)
  34. if ( false !== $nearest_station_selected && false !== $themes_selected ) {
  35. $locations_query_args['tax_query']['relation'] = 'AND';
  36. }
  37.  
  38. // Process query
  39. $locations_query = new WP_Query( $locations_query_args );
Add Comment
Please, Sign In to add comment