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.