searchwp\query\before
4.0.0以降
\SearchWP\Query クエリが実行される直前、Mod がセットアップされる前に発火します。
パラメータ
| タイプ | パラメータ | デフォルト | 提供開始 |
|---|---|---|---|
| \SearchWP\Query | $query |
実行中のクエリ | 4.0.0 |
例
All hooks should be added to your custom SearchWP Customizations Plugin.
エンジンソースを条件付きで削除する
以下のスニペットは、GET変数が設定されている場合に、検索エンジンから投稿ソースを条件付きで削除する方法を示すアウトラインです。そのGET変数が設定されている場合、ソースがエンジンから削除されているため、投稿は検索結果から除外されます。
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 | |
| // Conditionally remove a SearchWP Engine Source. | |
| add_filter( 'searchwp\query\before', function( $query ) { | |
| // Applies only if `myflag` GET variable exists. | |
| if ( ! isset( $_GET['myflag'] ) ) { | |
| return; | |
| } | |
| // Remove Posts from Engine. | |
| $source = \SearchWP\Utils::get_post_type_source_name( 'post' ) | |
| $query->get_engine()->remove_source( $source ); | |
| }, 20, 2 ); |

