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)) {
    		return;
    	}
    	
    	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:
    		// https://fulltextsearch.org/docs/wpfts-api-description/extended-wp_query/
    
    		$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

  • 0 Votes
    2 Posts
    272 Views
    EpsilonAdminE
    Hi @Simply_Friend Thank you for the question. Actually it's not planned to be added to the plugin core, because this feature (search by date FROM - TO) is already implemented in WP Native search (in WP_Query()). So you can search with date using WP_Query parameter date_query. Here is the topic: https://developer.wordpress.org/reference/classes/wp_query/#date-parameters Another question is if you want date picker fields to be added next to the text query field in the search widget. This is fairly easy to do for the average WP developer. There are probably some visual constructors to do this, but I can’t recommend anything here - if you find a solution, please write. It will be useful for other users. We don't plan to add a search form builder to the core functionality of WPFTS because we don't want to compete with Elementor / Beaver Builder / Visual Builder etc etc, although we will probably do a detailed tutorial on how to use the builders to make a search widget with additional fields. Hope this helped you. Thanks!
  • how to add buttons to the search engine

    Frequently Asked Questions
    5
    1 Votes
    5 Posts
    815 Views
    EpsilonAdminE
    @guarani23 Can you send me access to your website to the private messages? I can make a code, it's really simple.
  • 0 Votes
    3 Posts
    1k Views
    I
    @epsilonadmin custom block. Here is info how to create block - https://www.advancedcustomfields.com/blog/acf-5-8-introducing-acf-blocks-for-gutenberg/ So we register new block, assigned fields for this block. We add block on page. When I try to search phrase from one of these field - page not added to search result
  • 0 Votes
    2 Posts
    956 Views
    EpsilonAdminE
    Hi, @wonderbuild Should be you are using the "WPFTS :: Live Search" widget. This widget is intended to show this live search data. If you don't want them, simply use the native WP Search widget. Hope it helps.
  • 0 Votes
    1 Posts
    976 Views
    No one has replied

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.

ewm-logo-450

The forum powered by NodeBB | Contributors