When I import an external calendar into HivePress, it adds the hidden bookings to the first list found for that provider. Then when I search for ads by available date, the first listing is hidden in the results, and the rest of the ads from that vendor are present in the search results. Here’s what I found in the plugin code (class-booking.php component):
public function set_search_clauses( $where, $query ) {
global $wpdb;
// Check query.
if ( ! $query->is_search() || $query->get( 'post_type' ) !== 'hp_listing' ) {
return $where;
}
if ( ! $query->is_main_query() && $query->get( 'meta_key' ) !== 'hp_featured' ) {
return $where;
}
// Check request context.
if ( ! hivepress()->request->get_context( 'booking_times' ) ) {
return $where;
}
// Get time range.
list($start_time, $end_time) = hivepress()->request->get_context( 'booking_times' );
if ( ! $start_time || ! $end_time ) {
return $where;
}
// Get subquery.
$placeholder = implode( ', ', array_fill( 0, count( $this->get_blocked_statuses() ), '%s' ) );
$subquery = $wpdb->prepare(
"SELECT COUNT(*) FROM {$wpdb->posts} AS bookings
INNER JOIN {$wpdb->postmeta} AS start_times ON ( bookings.ID = start_times.post_id )
INNER JOIN {$wpdb->postmeta} AS end_times ON ( bookings.ID = end_times.post_id )
WHERE bookings.post_status IN ( {$placeholder} ) AND bookings.post_type = %s
AND bookings.post_parent = {$wpdb->posts}.ID
AND start_times.meta_key = %s AND end_times.meta_key = %s
AND (
( CAST( start_times.meta_value AS SIGNED ) BETWEEN %d and %d )
OR ( CAST( end_times.meta_value AS SIGNED ) BETWEEN %d and %d )
OR (
( CAST( start_times.meta_value AS SIGNED ) < %d )
AND ( CAST( end_times.meta_value AS SIGNED ) > %d )
)
)",
array_merge(
$this->get_blocked_statuses(),
[
'hp_booking',
'hp_start_time',
'hp_end_time',
$start_time,
$end_time - 1,
$start_time + 1,
$end_time,
$start_time,
$end_time,
]
)
);
// Add clause.
$where .= " AND ( {$subquery} ) = 0";
return $where;
}
What I mean:
For example, I have a vendor with ID 1000, he has 5 listings (1001, 1002, 1003, 1004, 1005). When importing an external calendar in which the date May 11, 2024 is occupied, a hidden booking with metadata is added to listing 1001 (the first one found):
hp_start_time: 1715385600
hp_end_time: 1715471999
And if you now search by the date of May 11, 2024, all listings of this vendor will be found in the search, except for 1001, which has a booking with the specified metadata. Logically, all 5 vendor listings should be excluded from the search. The “Manage availability per vendor” option is enabled.