diff --git a/viator-collector.zip b/viator-collector.zip index fa293a3..5d0bba9 100644 Binary files a/viator-collector.zip and b/viator-collector.zip differ diff --git a/viator-collector/includes/class-vc-display.php b/viator-collector/includes/class-vc-display.php index da13687..5fca79d 100644 --- a/viator-collector/includes/class-vc-display.php +++ b/viator-collector/includes/class-vc-display.php @@ -289,7 +289,7 @@ class VC_Display { */ public static function build_query_vars( array $base_tax = array() ) { $f = self::get_filter_state(); - $vars = array( 'posts_per_page' => 12 ); + $vars = array( 'posts_per_page' => 12, 'ignore_sticky_posts' => true ); if ( '' !== $f['q'] ) { $vars['s'] = $f['q']; @@ -346,46 +346,39 @@ class VC_Display { if ( $f['sellout'] ) { $meta_query[] = array( 'key' => '_vc_flags', 'value' => 'LIKELY_TO_SELL_OUT', 'compare' => 'LIKE' ); } - // Featured tours always sort first, whatever the chosen sort. OR/NOT - // EXISTS keeps non-featured tours in the results too. - $meta_query['vc_featured'] = array( - 'relation' => 'OR', - array( 'key' => '_vc_featured', 'value' => '1', 'compare' => '=' ), - array( 'key' => '_vc_featured', 'compare' => 'NOT EXISTS' ), - ); - - $orderby = array( 'vc_featured' => 'DESC' ); - + // Sort. Performance: the default (newest) orders by post date only — no + // postmeta JOIN and no featured/review tiebreak — so the unfiltered + // archive stays fast even with a very large catalogue (tens of thousands + // of tours). Price/rating sorts add a single meta_key JOIN, on demand. switch ( $f['sort'] ) { case 'price_asc': - $meta_query['vc_price'] = array( 'key' => '_vc_price_from', 'type' => 'DECIMAL', 'compare' => 'EXISTS' ); - $orderby['vc_price'] = 'ASC'; + $vars['meta_key'] = '_vc_price_from'; + $vars['orderby'] = 'meta_value_num'; + $vars['order'] = 'ASC'; break; case 'price_desc': - $meta_query['vc_price'] = array( 'key' => '_vc_price_from', 'type' => 'DECIMAL', 'compare' => 'EXISTS' ); - $orderby['vc_price'] = 'DESC'; + $vars['meta_key'] = '_vc_price_from'; + $vars['orderby'] = 'meta_value_num'; + $vars['order'] = 'DESC'; break; case 'rating': - $meta_query['vc_rating_sort'] = array( 'key' => '_vc_rating', 'type' => 'DECIMAL', 'compare' => 'EXISTS' ); - $orderby['vc_rating_sort'] = 'DESC'; + $vars['meta_key'] = '_vc_rating'; + $vars['orderby'] = 'meta_value_num'; + $vars['order'] = 'DESC'; break; + default: + $vars['orderby'] = 'date'; + $vars['order'] = 'DESC'; } - // Keep the selected sort as the primary order, then prefer the more - // established tour when two products otherwise rank the same. - $meta_query['vc_reviews_sort'] = array( - 'key' => '_vc_review_count', - 'type' => 'NUMERIC', - 'compare' => 'EXISTS', - ); - $orderby['vc_reviews_sort'] = 'DESC'; - $orderby['date'] = 'DESC'; // stable tiebreak - - if ( count( $meta_query ) > 1 ) { - $meta_query['relation'] = 'AND'; + // Only attach a meta_query when a filter is actually active, so the plain + // archive query carries no postmeta joins at all. + if ( ! empty( $meta_query ) ) { + if ( count( $meta_query ) > 1 ) { + $meta_query['relation'] = 'AND'; + } + $vars['meta_query'] = $meta_query; } - $vars['meta_query'] = $meta_query; - $vars['orderby'] = $orderby; return $vars; } diff --git a/viator-collector/viator-collector.php b/viator-collector/viator-collector.php index 0a6d035..939b2a9 100644 --- a/viator-collector/viator-collector.php +++ b/viator-collector/viator-collector.php @@ -4,13 +4,13 @@ defined('ABSPATH') || exit; /** * Plugin Name: Viator Collector * Description: Import Viator tours using the Viator Partner API and display them with native WordPress post types, templates, and shortcodes. - * Version: 1.8.3 + * Version: 1.8.4 * Author: Amir Bagheri * License: GPL-2.0-or-later * Text Domain: viator-collector */ -define('VC_VERSION', '1.8.3'); +define('VC_VERSION', '1.8.4'); define('VC_PLUGIN_FILE', __FILE__); define('VC_PLUGIN_DIR', plugin_dir_path(__FILE__)); define('VC_PLUGIN_URL', plugin_dir_url(__FILE__));