PluginProbe
Yatra – Travel Booking & Tour Operator Software / trunk
Yatra – Travel Booking & Tour Operator Software vtrunk
3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 2.0.11 All 82 releases
← All changes | app/Shortcodes/ActivityShortcode.php +32 -10 3.0.3trunk View file →
@@ -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 * Activity Shortcode
@@ -22,10 +23,14 @@
22 23 'show_trip_count' => 'yes',
23 24 'show_description' => 'yes',
24 25 'show_image' => 'yes',
25 26 'show_pagination' => 'yes', // Default to show pagination like trip shortcode
26 - 'activity' => '', // Specific activity slug(s), comma separated
27 - 'hide_empty' => 'yes',
27 + 'activity' => '', // Classification IDs, comma-separated
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',
28 33 'title' => 'Activity Listings'
29 34 ]);
30 35 }
31 36
@@ -109,12 +114,16 @@
109 114 'order_by' => 'name',
110 115 'order' => $atts['order'] === 'asc' ? 'ASC' : 'DESC'
111 116 ];
112 117
113 - // Filter by specific activities if provided
114 - if (!empty($atts['activity'])) {
115 - $args['where']['slug'] = explode(',', $atts['activity']);
116 - }
118 + $args['where'] = $args['where'] ?? [];
119 + TripListingFilterBuilder::applyTaxonomyWhere(
120 + $args['where'],
121 + $atts,
122 + 'activityIds',
123 + 'activity_ids',
124 + 'activity'
125 + );
117 126
118 127 // Get total count for pagination
119 128 $count_args = $args;
120 129 unset($count_args['limit']);
@@ -253,12 +262,25 @@
253 262 'difficulty' => !empty($difficulties) ? $this->getMostCommonDifficulty($difficulties) : null
254 263 ];
255 264 }
256 265
257 - // 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.
258 278 if ($atts['hide_empty'] === 'yes') {
259 - $activities = array_filter($activities, function($activity) {
260 - 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);
261 283 });
262 284 }
263 285
264 286 // Calculate pagination data
@@ -355,9 +377,9 @@
355 377 if (function_exists('yatra_get_activity_permalink')) {
356 378 return yatra_get_activity_permalink($activity);
357 379 }
358 380
359 - $base = SettingsService::getString('activity_base', 'activity');
381 + $base = SettingsService::getActivityBase();
360 382 return home_url('/' . $base . '/' . $activity->slug . '/');
361 383 }
362 384
363 385 return '#'; // Fallback