| @@ -24,9 +24,13 @@ | ||
| 24 | 24 | 'show_description' => 'yes', |
| 25 | 25 | 'show_image' => 'yes', |
| 26 | 26 | 'show_pagination' => 'yes', // Default to show pagination like trip shortcode |
| 27 | 27 | 'activity' => '', // Classification IDs, comma-separated |
| 28 | - 'hide_empty' => 'yes', | |
| 28 | + // hide_empty defaults to 'no' to preserve the historical | |
| 29 | + // behavior (show every activity, even ones with zero | |
| 30 | + // trips). Operators that prefer the empty-archive defense | |
| 31 | + // opt in with hide_empty="yes". | |
| 32 | + 'hide_empty' => 'no', | |
| 29 | 33 | 'title' => 'Activity Listings' |
| 30 | 34 | ]); |
| 31 | 35 | } |
| 32 | 36 | |
| @@ -258,12 +262,25 @@ | ||
| 258 | 262 | 'difficulty' => !empty($difficulties) ? $this->getMostCommonDifficulty($difficulties) : null |
| 259 | 263 | ]; |
| 260 | 264 | } |
| 261 | 265 | |
| 262 | - // Filter out empty activities if requested | |
| 266 | + // Filter out activities that have no published trips. | |
| 267 | + // | |
| 268 | + // Previously this only checked term name/slug presence — | |
| 269 | + // which never actually fires because all valid terms have | |
| 270 | + // both. As a result the shortcode would render activity | |
| 271 | + // cards with "0 trips" badges, leading users to click | |
| 272 | + // into empty archive pages. With hide_empty=yes we now | |
| 273 | + // drop any activity whose trip_count (computed above | |
| 274 | + // from TripClassificationsTable JOIN TripsTable WHERE | |
| 275 | + // status=publish) is zero. Term-metadata sanity is also | |
| 276 | + // preserved as a secondary safety check so we don't | |
| 277 | + // render orphan terms. | |
| 263 | 278 | if ($atts['hide_empty'] === 'yes') { |
| 264 | - $activities = array_filter($activities, function($activity) { | |
| 265 | - return !empty($activity['term']->name) && !empty($activity['term']->slug); | |
| 279 | + $activities = array_filter($activities, static function ($activity) { | |
| 280 | + return (int) ($activity['trip_count'] ?? 0) > 0 | |
| 281 | + && !empty($activity['term']->name) | |
| 282 | + && !empty($activity['term']->slug); | |
| 266 | 283 | }); |
| 267 | 284 | } |
| 268 | 285 | |
| 269 | 286 | // Calculate pagination data |