SearchWP

searchwp\auto_update_providers

Since: 4.1.8

Table of Contents

Note: This hook is applicable only when manually switching sites in a Multisite environment.

SearchWP is able to perform Multisite searches but if you are manually switching sites using switch_to_blog() you must tell SearchWP about it.

This does not happen automatically and is an opt-in requirement when using switch_to_blog()!

Without this hook in place, SearchWP will not return the correct results should you manually switch_to_blog() and execute a \SWP_Query.

Parameters

Type Parameter Default Since
Boolean $enabled false 4.1.8

Examples

All hooks should be added to your custom SearchWP Customizations Plugin.

Manually switching sites in a Multisite environment

<?php
// Tell SearchWP to automatically update its providers when switching sites.
// @link https://searchwp.com/documentation/hooks/searchwp-auto_update_providers/
add_filter( 'searchwp\auto_update_providers', '__return_true' );
// Retrieve results from this site.
$searchwp_site_1 = new \SWP_Query( [
's' => 'coffee',
] );
// Retrieve results from site 2.
switch_to_blog( 2 );
$searchwp_site_2 = new \SWP_Query( [
's' => 'coffee',
] );
// Restore the original site.
restore_current_blog();
[wpforms id="3080"]