searchwp\auto_update_providers
Da: 4.1.8
Indice
Nota: Questo hook è applicabile solo quando si cambiano manualmente i siti in un ambiente Multisite.
SearchWP è in grado di eseguire ricerche Multisite ma se stai cambiando manualmente i siti usando switch_to_blog() devi dirlo a SearchWP.
Questo non avviene automaticamente ed è un requisito di opt-in quando si usa switch_to_blog()!
Senza questo hook, SearchWP non restituirà i risultati corretti se cambi manualmente switch_to_blog() ed esegui una \SWP_Query.
Parametri
| Tipo | Parametro | Predefinito | Da |
|---|---|---|---|
| Booleano | $enabled |
false |
4.1.8 |
Esempi
All hooks should be added to your custom SearchWP Customizations Plugin.
Cambiare manualmente i siti in un ambiente Multisite
| <?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(); |

