Hi Mario,
Thanks for writing back and for sharing further details.
If your goal is to combine the input values from the custom search fields, so that it can be used as the actual text search field's input (i.e. "N° Département" field), I'll suggest following steps:
1. Since you'll be using the custom search fields to pass the values through the URL parameter, you'll need to set view's "Custom Search Settings" to "Full page refresh when visitors click on the search button" option. This approach won't work with AJAX results update.
2. To dynamically generate custom search fields ( e.g. Nom, Ville and Code Postal etc) so that their values are retained after the search page refreshes, you can add the following code into your active theme's "functions.php" file:
add_shortcode('show_custom_search_field', 'show_custom_search_field_fn');
function show_custom_search_field_fn($atts) {
$name = $atts['name'];
$label = $atts['label'];
$placeholder = $atts['placeholder'];
$value = '';
if(!empty($_GET[$name]))
{
$value = $_GET[$name];
}
ob_start();
?>
<div class="form-group">
<label><?php echo $label; ?></label>
<input type="text" name="<?php echo $name; ?>" value="<?php echo $value; ?>" class="js-wpv-filter-trigger-delayed form-control" placeholder="<?php echo $placeholder; ?>">
</div>
<?php
return ob_get_clean();
}
3. This newly registered shortcode can be used like this to add each search field in the "Search and Pagination" section.
For example:
[show_custom_search_field name="field-1" label="Field 1" placeholder="Enter value for field 1"]
As a result, you'll have a new custom search field in your search form and you can repeat the same for all custom search fields.
4. If you're using custom search fields to prepare a string for search results, it would make sense to hide the actual search field using custom CSS code and show visitors only these custom fields.
5. The last step would be to use "wpv_filter_query" function ( ref: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query ) to filter the view's query so that it uses the string combined from all the custom search fields, as the main searched term. You can add the following code in the theme's "functions.php" file:
add_filter( 'wpv_filter_query', 'filter_search_custom_fn', 1000 , 3 );
function filter_search_custom_fn( $query_args, $view_settings ) {
if ( ( !is_admin() && isset($view_settings['view_id'] ) ) && ( $view_settings['view_id'] == 12000070 ) )
{
$customString = "";
// get value from field 1
if(!empty($_GET['field-1'])) {
$customString .= urlencode($_GET['field-1']);
}
// get value from field 2
if(!empty($_GET['field-2'])) {
$customString .= ' '.urlencode($_GET['field-2']);
}
// get value from field 3
if(!empty($_GET['field-3'])) {
$customString .= ' '.urlencode($_GET['field-3']);
}
// combine the values from the 3 fields
if(!empty($customString)) {
$query_args['s'] = trim($customString);
}
else
{
unset($query_args['s']);
}
}
return $query_args;
}
In the above code example, I've used 3 fields (with names field-1, field-2 , field-3), but you'll replace these with the actual field names used on your website.
Please also make sure that view ID "12000070" is correct and corresponds to the actual view in use.
I hope this helps and please let me know if you have a question related to any of these steps.
regards,
Waqar