searchwp\query\mods
4.0.0以降
検索中に適用される\SearchWP\Modをカスタマイズします。
注意: クエリに存在する可能性のあるいくつかの内部\SearchWP\Modがあります。このフックでは、ユーザー定義の\SearchWP\Modのみをフィルタリングでき、ミッションクリティカルな\SearchWP\Modのフィルタリングは許可されていません。
内部については、searchwp\query\do_source_db_whereも参照してください。
パラメータ
| タイプ | パラメータ | デフォルト | 提供開始 |
|---|---|---|---|
| \SearchWP\Mod[] | $mods |
[] |
4.0.0 |
| \SearchWP\Query | $query |
実行中のクエリ | 4.0.0 |
例
All hooks should be added to your custom SearchWP Customizations Plugin.
投稿ID145および投稿ID211を除外するModを構築します
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 | |
| add_filter( 'searchwp\query\mods', function( $mods, $query ) { | |
| // Retrieve Source name to use with Mod. | |
| $source = \SearchWP\Utils::get_post_type_source_name( 'post' ); | |
| // Build Mod to exclude Post ID 145 and Post ID 211. | |
| $mod = new \SearchWP\Mod( $source ); | |
| $mod->set_where( [ [ | |
| 'column' => 'id', | |
| 'value' => [ 145, 211 ], | |
| 'compare' => 'NOT IN', | |
| 'type' => 'NUMERIC', | |
| ] ] ); | |
| $mods[] = $mod; | |
| return $mods; | |
| }, 20, 2 ); | |
| // Execute search for 'coffee' using Mod enqueued above. | |
| $search = new \SearchWP\Query( 'coffee' ); | |
| $results = $search->results; // Array of results. |

