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.
マルチサイト環境でサイトを手動で切り替える
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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(); |

