Hey,
I’ve been using the HivePress AI to add some custom snippets as filters on the listings search page, which seems to have been working okay so far.
However, the following snippet which is supposed to check if the booking requests field is enabled produces results whereby 1 listing that is featured, but does requires manual approval for the Booking Request option is showing up, whilst the rest of the results that appear don’t require approval (which is correct) - So, I deem them as ‘instantly bookable’. (i.e. the featured listing shouldn’t appear here) - Can you please help me exclude the featured listing, unless it is also ‘instantly bookable’. I’m not sure if the Featured listing priority logic is interfering with my attempts.
I’ve got this snippet so far:
add_filter(
'hivepress/v1/forms/listing_filter',
function( $form ) {
$form['fields']['instant_only'] = [
'label' => esc_html__( 'Booking Type', 'hivepress' ),
'caption' => esc_html__( 'Show only instant-book listings', 'hivepress-bookings' ),
'type' => 'checkbox',
'default' => false,
'filterable' => true,
'_order' => 31,
];
return $form;
},
1000
);
add_action(
'pre_get_posts',
function( $query ) {
if (
is_admin() ||
! $query->is_main_query() ||
$query->get( 'post_type' ) !== 'hp_listing'
) {
return;
}
// Only apply when the filter checkbox is checked
if ( empty( $_GET['instant_only'] ) ) {
return;
}
$meta_query = $query->get( 'meta_query' );
if ( ! is_array( $meta_query ) ) {
$meta_query = [];
}
if ( ! isset( $meta_query['relation'] ) ) {
$meta_query['relation'] = 'AND';
}
$meta_query[] = [
'relation' => 'OR',
[
'key' => 'hp_booking_moderated',
'compare' => 'NOT EXISTS',
],
[
'key' => 'hp_booking_moderated',
'value' => '1',
'compare' => '!=',
],
];
$query->set( 'meta_query', $meta_query );
},
1000
);
Edit: The ones I really need are filters for verified vendors only, featured listings only, automatically accepted bookings only filters - the first and 3rd ones should exclude featured listings unless they’re also applicable.
Cheers,
Chris ![]()