diff --git a/wp-content/themes/homeproz/inc/template-functions.php b/wp-content/themes/homeproz/inc/template-functions.php index 35c11182..cdbb9448 100755 --- a/wp-content/themes/homeproz/inc/template-functions.php +++ b/wp-content/themes/homeproz/inc/template-functions.php @@ -228,3 +228,69 @@ function homeproz_get_option($key, $default = '') { return isset($options[$key]) ? $options[$key] : $default; } + +/** + * Get property locations that have active or pending properties + * + * @return array Array of term objects + */ +function homeproz_get_active_locations() { + // Get Active and Pending status term IDs + $active_term = get_term_by('slug', 'active', 'property_status'); + $pending_term = get_term_by('slug', 'pending', 'property_status'); + + $status_ids = array(); + if ($active_term) $status_ids[] = $active_term->term_id; + if ($pending_term) $status_ids[] = $pending_term->term_id; + + if (empty($status_ids)) { + // Fallback: return all non-empty locations if no status terms exist + return get_terms(array( + 'taxonomy' => 'property_location', + 'hide_empty' => true, + 'orderby' => 'name', + 'order' => 'ASC', + )); + } + + // Query properties with Active or Pending status + $properties = get_posts(array( + 'post_type' => 'property', + 'posts_per_page' => -1, + 'fields' => 'ids', + 'tax_query' => array( + array( + 'taxonomy' => 'property_status', + 'field' => 'term_id', + 'terms' => $status_ids, + ), + ), + )); + + if (empty($properties)) { + return array(); + } + + // Get unique location terms from these properties + $location_ids = array(); + foreach ($properties as $property_id) { + $terms = wp_get_post_terms($property_id, 'property_location', array('fields' => 'ids')); + if (!is_wp_error($terms)) { + $location_ids = array_merge($location_ids, $terms); + } + } + + $location_ids = array_unique($location_ids); + + if (empty($location_ids)) { + return array(); + } + + // Get the actual term objects + return get_terms(array( + 'taxonomy' => 'property_location', + 'include' => $location_ids, + 'orderby' => 'name', + 'order' => 'ASC', + )); +} diff --git a/wp-content/themes/homeproz/template-parts/components/hero-section.php b/wp-content/themes/homeproz/template-parts/components/hero-section.php index 9ee2ec15..0c2db0b0 100755 --- a/wp-content/themes/homeproz/template-parts/components/hero-section.php +++ b/wp-content/themes/homeproz/template-parts/components/hero-section.php @@ -43,15 +43,10 @@ $size_class = $size === 'small' ? 'hero-section--small' : 'hero-section--large'; // Prepare gallery data attribute for JS $gallery_data = !empty($gallery_images) ? esc_attr(wp_json_encode($gallery_images)) : ''; -// Get locations for dropdown if needed +// Get locations for dropdown if needed (only locations with active/pending properties) $locations = array(); if ($show_location_search) { - $locations = get_terms(array( - 'taxonomy' => 'property_location', - 'hide_empty' => false, - 'orderby' => 'name', - 'order' => 'ASC', - )); + $locations = homeproz_get_active_locations(); } ?> diff --git a/wp-content/themes/homeproz/template-parts/property/property-filters.php b/wp-content/themes/homeproz/template-parts/property/property-filters.php index 6f269062..6c1508eb 100755 --- a/wp-content/themes/homeproz/template-parts/property/property-filters.php +++ b/wp-content/themes/homeproz/template-parts/property/property-filters.php @@ -22,7 +22,7 @@ $current_sort = isset($_GET['sort']) ? sanitize_text_field($_GET['sort']) : 'new // Get taxonomy terms $property_types = get_terms(array('taxonomy' => 'property_type', 'hide_empty' => false)); $property_statuses = get_terms(array('taxonomy' => 'property_status', 'hide_empty' => false)); -$property_locations = get_terms(array('taxonomy' => 'property_location', 'hide_empty' => false)); +$property_locations = homeproz_get_active_locations(); ?>