Get WPFTS Pro today with 25% discount!

Is it possible to make 2 different searches on the same website?

  • Yes, actually you can make more than one search, the number of search filters is not limited.

    Each search filter can have it's own preset, which can be selected in the "WPFTS :: Live Search" widget option and thus will be automatically activated when someone makes a search with this specific widget instance.

    Let me explain to you in two words how to do this.

    Imagine, you want to have 2 different searches on your website: the main search (which searches for posts and pages only) and another search that will search for PDF files only.

    Okay, let's say we already have the main search configured, we only need to disable the "Search in Files" option (available in WPFTS Settings > Search & Output > Filter).

    Let's create another search filter that will search in PDF files only.

    add_action ('init', function()
    	global $wpfts_core;
    	if ((!is_object($wpfts_core)) || (!$wpfts_core)) {
    	if (method_exists($wpfts_core, 'AddWidgetPreset')) {
    		// Repeat this block as much as you need
    		$wpfts_core->AddWidgetPreset('pdfonly', array(	// 'pdfonly' is the ID of your preset
    			'title' => 'PDF Only',		// This is a title of your preset (shown in WPFTS :: Live Search selector)
    			'filter' => 'pdfonly',		// This is the ID or the filter (can be the same as the preset name)
    			'results_url' => '/',		// The results page URL, it should be existing URL on your website
    			'autocomplete_mode' => 1,	// Should autosuggestion be ON for this widget?
    		// Put another preset here if you need that
    		// ...
    }, 255);

    Not hard, right? But that's not all. Now we need to force some WP_Query() parameters in case someone uses this preset.

    add_action('wpfts_pre_get_posts', function(&$wpq, $wdata)
    	// The filter processor for the custom widget
    	if ($wdata['id'] == 'pdfonly') {	// Use your filter name here (not preset name, however they can be the same)
    		// Let's set up specific parameters for this filter
    		// Please refer to WP_Query() official documentation for possible parameters
                    // The WPFTS-specific parameters also will work here, check this link for them:
    		$wpq->set('post_type', 'attachment');
    		$wpq->set('post_status',  array('inherit'));
    	// Repeat the filter processor block for each your widget
    	// ...
    }, 20, 2);

    Here is it. You need to place this code in the functions.php file of your current theme.

    When it's done, you can place the WPFTS :: Live Search widget to the specific page and then select your preset ("PDF Only" in our case) from the select box.

Suggested Topics

Be the first to read the news!

We are always improving our products, adding new functions and fixes. Subscribe now to be the first to get the updates and stay informed about our sales! We are not spammy. Seriously.

Join Us Now!

We are a professional IT-team. Many of us have been working in a Web IT field for more than 10 years. Our advanced experience of software development has been employed in the creation of the WordPress FullText Search plugin. All solutions implemented into the plugin have been used for 5 or more years in over 60 different web-projects.

We are looking forward to your comments, requests and suggestions in relation to the current plugin and future updates.


The forum powered by NodeBB | Contributors