SearchWP

This Documentation is for SearchWP Version 3

Available since: 1.0.6

searchwp_engine_settings_{engine}

View Parameters »

There are some use cases where you’d like to adjust engine settings at runtime based on search query terms or other factors. Use your engine name at the end of this filter to do just that.

Note: You must replace {engine} with the proper search engine name. The default search engine’s name is default.

Example: To change the keyword weight for titles given a specific search query, add the following to your active theme’s functions.php:

<?php
function my_searchwp_engine_settings_default( $settings, $query ) {
// print_r( $query ); // uncomment this line to see the query structure
// if the visitor searched for soccer, boost the title weight a bit
if( in_array( 'soccer', $query ) ) {
// print_r( $settings ); // uncomment this line to see the settings structure
if( isset( $settings['post']['weights']['title'] ) ) {
$settings['post']['weights']['title'] = 15;
}
}
return $settings;
}
add_filter( 'searchwp_engine_settings_default', 'my_searchwp_engine_settings_default', 10, 2 );
view raw gistfile1.php hosted with ❤ by GitHub

Parameters

Parameter Type Description
$settings Array

The existing search engine settings, as defined on the SearchWP settings screen

$query Array

The search terms for the current search

[wpforms id="3080"]