empty (All) > custom_directory (only if exactly one) // Only auto-select directory if there's exactly ONE directory in custom_directory $directory_type = ! empty( $_GET['directory_type'] ?? '' ) ? $_GET['directory_type'] : ( ( ! empty( $custom_directory ) && count( $custom_directory ) === 1 ) ? ( $custom_directory[0] ?? '' ) : '' ); if ( ! empty( $custom_directory ) ) { $directory_types = $custom_directory; } // Initialize taxonomy variables $adqs_cat_terms = []; $adqs_location_terms = []; // Taxonomies are now static and shared across all post types $category_taxonomy = 'adqs_category'; $location_taxonomy = 'adqs_location'; // Load terms for each taxonomy - filter by directory if custom_directory is specified $term_args = [ 'taxonomy' => $category_taxonomy ]; // If custom_directory is specified, filter terms to only those used by selected directories if ( ! empty( $custom_directory ) && is_array( $custom_directory ) ) { // Get post types for selected directories $directory_post_types = []; foreach ( $custom_directory as $dir_slug ) { $post_type = adqs_get_post_type_by_directory( $dir_slug ); if ( ! empty( $post_type ) && post_type_exists( $post_type ) ) { $directory_post_types[] = $post_type; } } if ( ! empty( $directory_post_types ) ) { // Query posts to find which terms are actually used $posts_query = new WP_Query( [ 'post_type' => $directory_post_types, 'posts_per_page' => -1, 'fields' => 'ids', 'post_status' => 'publish', ] ); if ( $posts_query->have_posts() ) { // Get category terms used by these posts $cat_term_ids = []; foreach ( $posts_query->posts as $post_id ) { $post_cats = wp_get_post_terms( $post_id, $category_taxonomy, [ 'fields' => 'ids' ] ); if ( ! is_wp_error( $post_cats ) && ! empty( $post_cats ) ) { $cat_term_ids = array_merge( $cat_term_ids, $post_cats ); } } $cat_term_ids = array_unique( $cat_term_ids ); // Get location terms used by these posts $loc_term_ids = []; foreach ( $posts_query->posts as $post_id ) { $post_locs = wp_get_post_terms( $post_id, $location_taxonomy, [ 'fields' => 'ids' ] ); if ( ! is_wp_error( $post_locs ) && ! empty( $post_locs ) ) { $loc_term_ids = array_merge( $loc_term_ids, $post_locs ); } } $loc_term_ids = array_unique( $loc_term_ids ); // Load filtered terms if ( ! empty( $cat_term_ids ) && taxonomy_exists( $category_taxonomy ) ) { $adqs_cat_terms = get_terms( [ 'taxonomy' => $category_taxonomy, 'include' => $cat_term_ids, ] ); } if ( ! empty( $loc_term_ids ) && taxonomy_exists( $location_taxonomy ) ) { $adqs_location_terms = get_terms( [ 'taxonomy' => $location_taxonomy, 'include' => $loc_term_ids, ] ); } } wp_reset_postdata(); } } else { // No custom_directory specified, load all terms if ( taxonomy_exists( $category_taxonomy ) ) { $adqs_cat_terms = adqs_get_terms( $category_taxonomy ); } if ( taxonomy_exists( $location_taxonomy ) ) { $adqs_location_terms = adqs_get_terms( $location_taxonomy ); } } $get_alllistingspage_id = absint( get_option( 'adqs_all_listings_page', 0 ) ); if ( empty( $search_page_url ) ) { $search_page_url = get_permalink( $get_alllistingspage_id ); } // Get style type $style_type = $args['style_type'] ?? ''; ?>