| @@ -22,9 +22,13 @@ | ||
| 22 | 22 | 'show_description' => 'yes', |
| 23 | 23 | 'show_image' => 'yes', |
| 24 | 24 | 'show_pagination' => 'yes', |
| 25 | 25 | 'category' => '', // Classification IDs, comma-separated |
| 26 | - 'hide_empty' => 'yes', | |
| 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', | |
| 27 | 31 | 'featured_only' => 'no', |
| 28 | 32 | 'title' => 'Trip Categories', |
| 29 | 33 | ]); |
| 30 | 34 | } |
| @@ -219,11 +223,24 @@ | ||
| 219 | 223 | 'best_season' => $best_season, |
| 220 | 224 | ]; |
| 221 | 225 | } |
| 222 | 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. | |
| 223 | 238 | if (($atts['hide_empty'] ?? 'yes') === 'yes') { |
| 224 | 239 | $categories = array_filter($categories, static function ($row) { |
| 225 | - 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); | |
| 226 | 243 | }); |
| 227 | 244 | } |
| 228 | 245 | |
| 229 | 246 | if (($atts['featured_only'] ?? 'no') === 'yes') { |