diff --git a/viator-collector.zip b/viator-collector.zip index 3447623..d25d8aa 100644 Binary files a/viator-collector.zip and b/viator-collector.zip differ diff --git a/viator-collector/includes/class-vc-taxonomies.php b/viator-collector/includes/class-vc-taxonomies.php index 2b1b0c2..e222ced 100644 --- a/viator-collector/includes/class-vc-taxonomies.php +++ b/viator-collector/includes/class-vc-taxonomies.php @@ -102,7 +102,7 @@ class VC_Taxonomies { } else { update_term_meta( $term_id, '_vc_image_url', $url ); } - delete_transient( 'vc_term_img_' . absint( $term_id ) ); + delete_transient( 'vc_term_img2_' . absint( $term_id ) ); } public static function register() { diff --git a/viator-collector/includes/helpers.php b/viator-collector/includes/helpers.php index 776b996..237a07b 100644 --- a/viator-collector/includes/helpers.php +++ b/viator-collector/includes/helpers.php @@ -177,7 +177,9 @@ function vc_term_image_url( $term_id, $taxonomy = '' ) { return $custom; } - $cache_key = 'vc_term_img_' . $term_id; + // "img2": the v1 key cached empty results for 12h, which left cards blank + // long after their tours had photos. Empty results now expire in an hour. + $cache_key = 'vc_term_img2_' . $term_id; $cached = get_transient( $cache_key ); if ( false !== $cached ) { return $cached; @@ -192,10 +194,14 @@ function vc_term_image_url( $term_id, $taxonomy = '' ) { $url = ''; if ( $taxonomy ) { + // A few recent tours in the term; the first with any photo wins. The + // photo is read in PHP (primary, else first gallery image) — the same + // fallback the tour cards use — rather than filtered in SQL. $query = new WP_Query( array( 'post_type' => 'viator_tour', - 'posts_per_page' => 1, + 'post_status' => 'publish', + 'posts_per_page' => 10, 'fields' => 'ids', 'no_found_rows' => true, 'update_post_term_cache' => false, @@ -206,21 +212,21 @@ function vc_term_image_url( $term_id, $taxonomy = '' ) { 'terms' => $term_id, ), ), - 'meta_query' => array( - array( - 'key' => '_vc_primary_image_url', - 'value' => '', - 'compare' => '!=', - ), - ), ) ); - if ( ! empty( $query->posts ) ) { - $url = (string) get_post_meta( (int) $query->posts[0], '_vc_primary_image_url', true ); + foreach ( $query->posts as $post_id ) { + $url = (string) get_post_meta( (int) $post_id, '_vc_primary_image_url', true ); + if ( '' === $url ) { + $gallery = vc_json_decode_meta( get_post_meta( (int) $post_id, '_vc_gallery_image_urls', true ), array() ); + $url = $gallery ? (string) reset( $gallery ) : ''; + } + if ( '' !== $url ) { + break; + } } } - set_transient( $cache_key, $url, 12 * HOUR_IN_SECONDS ); + set_transient( $cache_key, $url, '' !== $url ? 12 * HOUR_IN_SECONDS : HOUR_IN_SECONDS ); return $url; } diff --git a/viator-collector/viator-collector.php b/viator-collector/viator-collector.php index b9a3cf8..c32f095 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.9.2 + * Version: 1.9.3 * Author: Amir Bagheri * License: GPL-2.0-or-later * Text Domain: viator-collector */ -define('VC_VERSION', '1.9.2'); +define('VC_VERSION', '1.9.3'); define('VC_PLUGIN_FILE', __FILE__); define('VC_PLUGIN_DIR', plugin_dir_path(__FILE__)); define('VC_PLUGIN_URL', plugin_dir_url(__FILE__));