Need Hooks for Filter - Datepicker (For more flexibility)

Hello, This is a very specific question and probably requires a code snippet. However, I’m unable to modify the URL and change its format.

For example, natively in Bricks, I have this: ?_date=2025-04-23%2C2025-04-25

What I want is to modify the URL using a code snippet to get this:
?_date=checkin_checkout!date:2025.4.23-2025.4.25

// FILE: bricks-date-to-jetsmart.php
add_action('bricks/filters/init', 'integrate_jetsmart_date_filter');

function integrate_jetsmart_date_filter() {
    // 1. Register custom filter type (if needed)
    if (function_exists('bricks_register_filter')) {
        bricks_register_filter([
            'name' => 'jetsmart_date',
            'label' => 'JetSmart Date',
            'apply' => 'apply_jetsmart_date_filter',
        ]);
    }

    // 2. Hook into Bricks' query system
    add_filter('bricks/query/run', 'modify_bricks_date_query', 10, 2);
}

function modify_bricks_date_query($query_args, $settings) {
    // Only process on the correct page template
    if (!is_page('property')) {
        return $query_args;
    }

    // Check for Bricks date parameter
    if (isset($_GET['_date']) && !empty($_GET['_date'])) {
        $date_value = sanitize_text_field($_GET['_date']);
        
        // Skip if already in correct format
        if (strpos($date_value, 'checkin_checkout!date:') !== false) {
            return $query_args;
        }

        // Convert date format
        $converted_date = preg_replace_callback(
            '/(\d{4})-(\d{2})-(\d{2})[,%2C](\d{4})-(\d{2})-(\d{2})/',
            function($matches) {
                return sprintf('checkin_checkout!date:%d.%d.%d-%d.%d.%d',
                    $matches[1], (int)$matches[2], (int)$matches[3],
                    $matches[4], (int)$matches[5], (int)$matches[6]
                );
            },
            urldecode($date_value)
        );

        // Update query parameters
        $query_args['meta_query'] = [
            [
                'key' => 'property_dates', // Match your custom field
                'value' => $converted_date,
                'compare' => 'LIKE'
            ]
        ];

        // Update URL parameter silently
        add_action('bricks/filters/after', function() use ($converted_date) {
            ?>
            <script>
            document.addEventListener('bricks/ajax/filters/init', function() {
                const url = new URL(window.location.href);
                if (url.searchParams.get('_date') !== <?php echo json_encode($converted_date); ?>) {
                    url.searchParams.set('_date', <?php echo json_encode($converted_date); ?>);
                    history.replaceState({}, '', url.toString());
                }
            });
            </script>
            <?php
        });
    }

    return $query_args;
}

As you can see, I’ve already tried several combinations, but I can’t get it to work. Something is probably missing… perhaps a specific hook that I am unaware of.
Unfortunately, the Bricks documentation doesn’t mention a way to modify the behavior of the “Filter - Datepicker.”

If anyone understands what’s missing or has a solution, thank you for sharing.
And if a developer happens to pass by and understands what’s going on, thank you as well for sharing a solution!

EDIT :
on the left jetsmartfilters on the right bricks filter
Datepicker

While the code clearly illustrates what I’m trying to achieve, I’d like to provide some additional context about the reasoning behind it. Datepicker could be far more flexible and adaptable to various external solutions if it offered parameters directly within Bricks, either as options or through new hooks.

My objective is to move away from Jetsmartfilters since the only element linking me to it is the date range used to locate the checkin_checkout properties (Jetbooking). Datepicker Bricks could handle this task perfectly if it were able to conform to the specific URL pattern required by Jetbooking.

Although I found this article in bricks academy, I consulted various AIs for a solution. However, it seems that something is missing, and none of the suggestions actually work. I am sharing everything here to help you visualize and understand the issue, with the aim of speeding up the process of identifying where the problem lies in making these snippet codes function properly.
------------------------------------------------------------------------------------------------------------------------------
claude.ai response
-------------------------------------------------------------------------------------------------------------------------------

This article discusses the Datepicker control in Bricks Builder, which might be related to your issue, but it doesn’t directly address your specific problem of converting date parameters in URLs from one format to another.

The article explains how to configure the Datepicker control when creating custom Bricks elements, focusing on the configuration options available like enableTime, altInput, and the new options property. It’s useful for understanding how to set up datepickers in custom elements, but it doesn’t cover URL parameter conversion or integration with JetSmartFilters.

For your specific issue, we need to intercept the date parameter that the Bricks datepicker is generating and modify it to the JetSmartFilters format. Let me provide a more targeted solution:

// Hook into WordPress early enough to catch query parameters
add_action('wp', 'intercept_bricks_datepicker_parameters', 5);

function intercept_bricks_datepicker_parameters() {
    // Bail if not on the property page or no date parameter
    if (!is_page('property') || !isset($_GET['_date'])) {
        return;
    }
    
    // Get the date parameter
    $bricks_date = sanitize_text_field($_GET['_date']);
    
    // Skip if already in JetSmartFilters format
    if (strpos($bricks_date, 'checkin_checkout!date:') !== false) {
        return;
    }
    
    // URL decode to handle encoded commas
    $bricks_date = urldecode($bricks_date);
    
    // Debug log
    error_log("Intercepted date parameter: " . $bricks_date);
    
    // Split by comma
    $dates = explode(',', $bricks_date);
    
    // Make sure we have two dates
    if (count($dates) !== 2) {
        error_log("Invalid date format (expected 2 dates): " . $bricks_date);
        return;
    }
    
    // Format the dates
    $formatted_dates = [];
    foreach ($dates as $date) {
        $parts = explode('-', trim($date));
        
        // Validate date parts
        if (count($parts) !== 3) {
            error_log("Invalid date part format: " . $date);
            return;
        }
        
        // Format as YYYY.M.D (removing leading zeros)
        $formatted_dates[] = sprintf(
            '%d.%d.%d',
            intval($parts[0]), 
            intval($parts[1]), 
            intval($parts[2])
        );
    }
    
    // Create JetSmartFilters format
    $jet_smart_date = 'checkin_checkout!date:' . implode('-', $formatted_dates);
    
    // Build the new URL
    $current_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    $base_url = remove_query_arg('_date', $current_url);
    $new_url = add_query_arg('_date', $jet_smart_date, $base_url);
    
    error_log("Redirecting from: " . $current_url);
    error_log("Redirecting to: " . $new_url);
    
    // Redirect if the URL has changed
    if ($new_url !== $current_url) {
        wp_safe_redirect($new_url);
        exit;
    }
}

If the issue is related to how Bricks processes the filter, you might also need to hook into the Bricks filter system. Here’s an alternative approach that might work better:

// Hook into Bricks filter system (if available)
add_action('init', 'setup_bricks_date_filter_hook');

function setup_bricks_date_filter_hook() {
    // Check if Bricks is active
    if (function_exists('Bricks\Query')) {
        add_filter('bricks/query/vars', 'convert_bricks_date_format', 10, 2);
        add_filter('bricks/query/run', 'convert_bricks_date_in_query', 10, 2);
    }
}

function convert_bricks_date_format($vars, $settings) {
    // Check if we have a date parameter
    if (isset($_GET['_date'])) {
        $bricks_date = sanitize_text_field($_GET['_date']);
        
        // Skip if already in JetSmartFilters format
        if (strpos($bricks_date, 'checkin_checkout!date:') !== false) {
            return $vars;
        }
        
        // Decode URL parameters
        $bricks_date = urldecode($bricks_date);
        
        // Split by comma
        $dates = explode(',', $bricks_date);
        
        // Make sure we have two dates
        if (count($dates) === 2) {
            $formatted_dates = [];
            foreach ($dates as $date) {
                $parts = explode('-', trim($date));
                
                // Validate date parts
                if (count($parts) === 3) {
                    // Format as YYYY.M.D (removing leading zeros)
                    $formatted_dates[] = sprintf(
                        '%d.%d.%d',
                        intval($parts[0]), 
                        intval($parts[1]), 
                        intval($parts[2])
                    );
                }
            }
            
            // If we successfully formatted both dates
            if (count($formatted_dates) === 2) {
                // Create JetSmartFilters format
                $jet_smart_date = 'checkin_checkout!date:' . implode('-', $formatted_dates);
                
                // Update the vars array with the new date format
                $vars['_date'] = $jet_smart_date;
                
                error_log("Converted Bricks date to JetSmartFilter format: " . $jet_smart_date);
            }
        }
    }
    
    return $vars;
}

function convert_bricks_date_in_query($query_args, $settings) {
    // Check if this query may be affected by our date filter
    if (isset($query_args['meta_query']) && isset($_GET['_date'])) {
        $bricks_date = sanitize_text_field($_GET['_date']);
        
        // Skip if already in JetSmartFilters format
        if (strpos($bricks_date, 'checkin_checkout!date:') === false) {
            // Convert the date using the same logic as above
            // (simplified to avoid code duplication)
            $bricks_date = urldecode($bricks_date);
            $dates = explode(',', $bricks_date);
            
            if (count($dates) === 2) {
                $formatted_dates = [];
                foreach ($dates as $date) {
                    $parts = explode('-', trim($date));
                    if (count($parts) === 3) {
                        $formatted_dates[] = sprintf(
                            '%d.%d.%d',
                            intval($parts[0]), 
                            intval($parts[1]), 
                            intval($parts[2])
                        );
                    }
                }
                
                if (count($formatted_dates) === 2) {
                    $jet_smart_date = 'checkin_checkout!date:' . implode('-', $formatted_dates);
                    
                    // Build the new URL
                    $current_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
                    $base_url = remove_query_arg('_date', $current_url);
                    $new_url = add_query_arg('_date', $jet_smart_date, $base_url);
                    
                    // Redirect if there's a difference
                    if ($new_url !== $current_url) {
                        wp_safe_redirect($new_url);
                        exit;
                    }
                }
            }
        }
    }
    
    return $query_args;
}

These approaches should catch and convert your date parameters. The article you shared is helpful in understanding how Bricks implements the datepicker, but for your specific URL parameter conversion need, we need to focus on intercepting and modifying the query parameters as shown above.