SearchWP Documentation

インストールガイドを表示したり、ナレッジベースを参照したり、SearchWPの多くのフックについて確認したりできます。

searchwp\auto_update_providers

提供開始: 4.1.8

注意: このフックは、マルチサイト環境でサイトを手動で切り替える場合にのみ適用されます。

SearchWPはマルチサイト検索を実行できますが、手動switch_to_blog()を使用してサイトを切り替える場合は、SearchWPにその旨を伝える必要があります

これは自動的には行われませんswitch_to_blog()を使用する際のオプトイン要件です!

このフックがない場合、手動でswitch_to_blog()を使用して\SWP_Queryを実行しても、SearchWPは正しい結果を返しません。

パラメータ

タイプ パラメータ デフォルト 提供開始
ブール値 $enabled false 4.1.8

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

マルチサイト環境でサイトを手動で切り替える

<?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();

このコードの使用方法