Skip Navigation

[Resolved] 4 input boxes for same text search form

This support ticket is created 5 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Mario Hernandez 5 years, 4 months ago.

Assisted by: Waqar.

Author
Posts
#1167115
Captura de pantalla 2018-12-16 a las 10.55.29.jpg
Captura de pantalla 2018-12-16 a las 10.55.20.png

Hi!

First of all we want to say that we are in love with Toolset and the great support team. Thank you!

We have a problem:

We need to create four input text search boxes because the people that will search in our directory needs the things to be understood easily.

Currently, we can create different input text boxes, but each one would find a unique custom field, except from the one that is "Text Search" with Relevanssi, that searches in all custom fields at the same time.

However, as you can see in the image, Toolset won't let us add another text search box.

We need to replicate the effect of the text search box in the other boxes (marked with green)

How can we approach to this?

hidden link

Thank you,

Mario

#1167585

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Mario,

Thank you for contacting us and I'll be happy to assist.

Your observation is correct and it is possible to use only one search text field, which is integrated with Relevanssi results.

Can you please clarify that If you don't want those extra text fields to be linked to a particular custom field value, where should they get the results from?

I'll be in a better position to share some alternative or a workaround, once I'll have more information about the role of those fields.

regards,
Waqar

#1167794

Hi Waqar,

thanks for your reply!

The last search box (N° Département (ex : 75, 92)) is the search text field, integrated with Relevanssi results.

Our need is that anytime when the user writes inside the other boxes (Nom, Ville and Code Postal) , the query sends the filled content to the last box, and then the page should show the results as if you have search directly in the last box.

I mean: The last box (view in red in the image in the first post), has the Relevanssi search function. We need that when you fill any of the other boxes, the query gets sent to the relevanssi search box.

My intuition is that a workaround would be to create three html boxes that replicate the last box, like this:

        <label>Filtrer par </label>
      		<div class="form-group recherchemembre">
				<label>Nom</label>
				<input type="text" name="wpv_post_search" class="js-wpv-filter-trigger-delayed searchmembers form-control" placeholder="Tapez entrée par rechercher">
	 	    </div>
      		<div class="form-group recherchemembre">
				<label>Ville</label>
				<input type="text" name="wpv_post_search" class="js-wpv-filter-trigger-delayed searchmembers form-control" placeholder="Tapez entrée par rechercher">
	 	    </div>
      		<div class="form-group recherchemembre">
				<label>Code Postal</label>
				<input type="text" name="wpv_post_search" class="js-wpv-filter-trigger-delayed searchmembers form-control" placeholder="Tapez entrée par rechercher">
	 	    </div>
      		<div class="form-group recherchemembre">
				<label>N° Département (ex : 75, 92)</label> 
				<input type="text" name="wpv_post_search" class="js-wpv-filter-trigger-delayed searchmembers form-control" placeholder="Tapez entrée par rechercher">
	 	    </div>      

However, I don't know the consequences of having the three extra boxes (Nom, Ville and Code Postal) to have the same code as the one that generates Toolset for the text search with Relevanssi results.

Is possible to copy and paste the last input box code to obtain the same results and same functionality as the last one?

We would do this to help the users to know that they can search by Nom, Ville and Code Postal.

Thank you very much,

Mario

#1168704

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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

#1168705

My issue is resolved with this great solution. Thank you for all your time and effort! Gold value!

Best,

Mario

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.