fix: destination cards show a tour photo again
vc_term_image_url() cached empty results for 12h and relied on an SQL meta comparison to find a tour with a photo; destination cards site-wide (homepage and region pages) were blank. Read the photo in PHP from up to 10 tours (primary, else first gallery image), use a fresh cache key, and expire empty results after an hour. Plugin 1.9.3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Binary file not shown.
@@ -102,7 +102,7 @@ class VC_Taxonomies {
|
|||||||
} else {
|
} else {
|
||||||
update_term_meta( $term_id, '_vc_image_url', $url );
|
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() {
|
public static function register() {
|
||||||
|
|||||||
@@ -177,7 +177,9 @@ function vc_term_image_url( $term_id, $taxonomy = '' ) {
|
|||||||
return $custom;
|
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 );
|
$cached = get_transient( $cache_key );
|
||||||
if ( false !== $cached ) {
|
if ( false !== $cached ) {
|
||||||
return $cached;
|
return $cached;
|
||||||
@@ -192,10 +194,14 @@ function vc_term_image_url( $term_id, $taxonomy = '' ) {
|
|||||||
|
|
||||||
$url = '';
|
$url = '';
|
||||||
if ( $taxonomy ) {
|
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(
|
$query = new WP_Query(
|
||||||
array(
|
array(
|
||||||
'post_type' => 'viator_tour',
|
'post_type' => 'viator_tour',
|
||||||
'posts_per_page' => 1,
|
'post_status' => 'publish',
|
||||||
|
'posts_per_page' => 10,
|
||||||
'fields' => 'ids',
|
'fields' => 'ids',
|
||||||
'no_found_rows' => true,
|
'no_found_rows' => true,
|
||||||
'update_post_term_cache' => false,
|
'update_post_term_cache' => false,
|
||||||
@@ -206,21 +212,21 @@ function vc_term_image_url( $term_id, $taxonomy = '' ) {
|
|||||||
'terms' => $term_id,
|
'terms' => $term_id,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'meta_query' => array(
|
|
||||||
array(
|
|
||||||
'key' => '_vc_primary_image_url',
|
|
||||||
'value' => '',
|
|
||||||
'compare' => '!=',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if ( ! empty( $query->posts ) ) {
|
foreach ( $query->posts as $post_id ) {
|
||||||
$url = (string) get_post_meta( (int) $query->posts[0], '_vc_primary_image_url', true );
|
$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;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ defined('ABSPATH') || exit;
|
|||||||
/**
|
/**
|
||||||
* Plugin Name: Viator Collector
|
* Plugin Name: Viator Collector
|
||||||
* Description: Import Viator tours using the Viator Partner API and display them with native WordPress post types, templates, and shortcodes.
|
* 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
|
* Author: Amir Bagheri
|
||||||
* License: GPL-2.0-or-later
|
* License: GPL-2.0-or-later
|
||||||
* Text Domain: viator-collector
|
* Text Domain: viator-collector
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define('VC_VERSION', '1.9.2');
|
define('VC_VERSION', '1.9.3');
|
||||||
define('VC_PLUGIN_FILE', __FILE__);
|
define('VC_PLUGIN_FILE', __FILE__);
|
||||||
define('VC_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
define('VC_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
||||||
define('VC_PLUGIN_URL', plugin_dir_url(__FILE__));
|
define('VC_PLUGIN_URL', plugin_dir_url(__FILE__));
|
||||||
|
|||||||
Reference in New Issue
Block a user