Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Set up default query
- $locations_query_args = [
- 'post_type' => 'locations',
- 'post_status' => 'publish',
- 'posts_per_page' => 500,
- ];
- // Add the search query if set ($town_city_selected)
- if ( false !== $town_city_selected ) {
- $locations_query_args['s'] = esc_attr( $town_city_selected );
- }
- // Set the nearest station if set
- if ( false !== $nearest_station_selected ) {
- $locations_query_args['tax_query'][] = [
- 'taxonomy' => 'nearest_station',
- 'field' => 'term_id',
- 'terms' => esc_attr( $nearest_station_selected ),
- ];
- }
- // Set the theme(s) if set
- if ( false !== $themes_selected ) {
- $locations_query_args['tax_query'][] = [
- 'taxonomy' => 'themes',
- 'field' => 'term_id',
- 'terms' => $themes_selected,
- ];
- }
- // If BOTH taxonomies (nearest station and theme(s)) have a value then this is a relation = AND query (we need to deal with both)
- if ( false !== $nearest_station_selected && false !== $themes_selected ) {
- $locations_query_args['tax_query']['relation'] = 'AND';
- }
- // Process query
- $locations_query = new WP_Query( $locations_query_args );
Add Comment
Please, Sign In to add comment