| @@ -3,8 +3,9 @@ | ||
| 3 | 3 | declare(strict_types=1); |
| 4 | 4 | |
| 5 | 5 | namespace Yatra\Shortcodes; |
| 6 | 6 | |
| 7 | +use Yatra\Helpers\TripListingFilterBuilder; | |
| 7 | 8 | use Yatra\Services\SettingsService; |
| 8 | 9 | |
| 9 | 10 | /** |
| 10 | 11 | * Trip category listing shortcode — same card UI as {@see DestinationShortcode}. |
| @@ -20,10 +21,14 @@ | ||
| 20 | 21 | 'show_trip_count' => 'yes', |
| 21 | 22 | 'show_description' => 'yes', |
| 22 | 23 | 'show_image' => 'yes', |
| 23 | 24 | 'show_pagination' => 'yes', |
| 24 | - 'category' => '', | |
| 25 | - 'hide_empty' => 'yes', | |
| 25 | + 'category' => '', // Classification IDs, comma-separated | |
| 26 | + // hide_empty defaults to 'no' to preserve the historical | |
| 27 | + // behavior (show every category, even ones with zero | |
| 28 | + // trips). Operators that prefer the empty-archive defense | |
| 29 | + // opt in with hide_empty="yes". | |
| 30 | + 'hide_empty' => 'no', | |
| 26 | 31 | 'featured_only' => 'no', |
| 27 | 32 | 'title' => 'Trip Categories', |
| 28 | 33 | ]); |
| 29 | 34 | } |
| @@ -99,11 +104,15 @@ | ||
| 99 | 104 | 'status' => 'publish', |
| 100 | 105 | ], |
| 101 | 106 | ]; |
| 102 | 107 | |
| 103 | - if (!empty($atts['category'])) { | |
| 104 | - $args['where']['slug'] = array_map('trim', explode(',', (string) $atts['category'])); | |
| 105 | - } | |
| 108 | + TripListingFilterBuilder::applyTaxonomyWhere( | |
| 109 | + $args['where'], | |
| 110 | + $atts, | |
| 111 | + 'categoryIds', | |
| 112 | + 'category_ids', | |
| 113 | + 'category' | |
| 114 | + ); | |
| 106 | 115 | |
| 107 | 116 | $count_args = $args; |
| 108 | 117 | unset($count_args['limit'], $count_args['offset']); |
| 109 | 118 | $total_categories = $categoryService->count($count_args); |
| @@ -214,11 +223,24 @@ | ||
| 214 | 223 | 'best_season' => $best_season, |
| 215 | 224 | ]; |
| 216 | 225 | } |
| 217 | 226 | |
| 227 | + // Filter out trip categories that have no published trips. | |
| 228 | + // | |
| 229 | + // See ActivityShortcode for the full rationale — the | |
| 230 | + // prior implementation only filtered on term-metadata | |
| 231 | + // emptiness (which never actually fires), so empty | |
| 232 | + // categories were rendered with "0 trips" badges and | |
| 233 | + // broken archive links. We now drop any category whose | |
| 234 | + // trip_count (computed above from | |
| 235 | + // TripClassificationsTable JOIN TripsTable WHERE | |
| 236 | + // status=publish) is zero, plus the original sanity | |
| 237 | + // check on name/slug. | |
| 218 | 238 | if (($atts['hide_empty'] ?? 'yes') === 'yes') { |
| 219 | 239 | $categories = array_filter($categories, static function ($row) { |
| 220 | - return !empty($row['term']->name) && !empty($row['term']->slug); | |
| 240 | + return (int) ($row['trip_count'] ?? 0) > 0 | |
| 241 | + && !empty($row['term']->name) | |
| 242 | + && !empty($row['term']->slug); | |
| 221 | 243 | }); |
| 222 | 244 | } |
| 223 | 245 | |
| 224 | 246 | if (($atts['featured_only'] ?? 'no') === 'yes') { |
| @@ -388,9 +410,9 @@ | ||
| 388 | 410 | |
| 389 | 411 | return $url !== '' ? $url : '#'; |
| 390 | 412 | } |
| 391 | 413 | |
| 392 | - $base = SettingsService::getString('trip_category_base', 'trip-category'); | |
| 414 | + $base = SettingsService::getTripCategoryBase(); | |
| 393 | 415 | |
| 394 | 416 | return isset($category->slug) ? home_url('/' . $base . '/' . $category->slug . '/') : '#'; |
| 395 | 417 | } |
| 396 | 418 | } |