SearchWP Documentation

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

searchwp\post_stati

4.0.0以降

\WP_Postベースのソースで考慮される投稿ステータスを制御します。

このフックが適切に有効になるためには、SearchWPのインデックスがどのように機能するかを理解する必要があることに注意してください。インデックスは、潜在的な結果の「最大」プールを表し、クエリはそのインデックスに対して実行され、返されるエントリが制限されます。

とはいえ、結果で返される投稿ステータスをカスタマイズするには、次の2つのステップに従う必要があります。

  1. インデックスを広げて、すべての該当する投稿ステータスを含める
  2. クエリにフックして、期待される投稿ステータスのみが返されるようにする

? 不適切な使用はデータ漏洩につながる可能性があるため、注意して進めてください!

パラメータ

タイプ パラメータ デフォルト 提供開始
String[] $post_stati 公開されており、検索から除外されていない投稿ステータス 4.0.0
配列 $args
キー タイプ
エンジン 文字列 エンジンの名前
4.0.0

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

補足エンジンに下書きを含める

<?php
/**
* Include Drafts in SearchWP Supplemental Engine results.
*
* NOTE: In order for this to work we need to first tell SearchWP to index
* ALL of the potential post stati. We can then curate which post stati
* to consider during searches; it is a two-step process.
*/
// Step 1: tell SearchWP to index Drafts in addition to its default post stati.
add_filter( 'searchwp\post_stati', function( $post_stati, $args ) {
$post_stati[] = 'draft';
return $post_stati;
}, 20, 2 );
// Step 2: limit post stati during searches, per post type. By default
// SearchWP is going to respect the stati we defined in Step 1!
add_filter( 'searchwp\query\mods', function( $mods, $query ) {
// If this is the 'supplemental' Engine, search all post stati.
if ( 'supplemental' === $query->get_engine()->get_name() ) {
return $mods;
}
// Only return WP_Posts with 'publish' post status.
foreach ( $query->get_engine()->get_sources() as $source ) {
$flag = 'post' . SEARCHWP_SEPARATOR;
if ( 'post.' !== substr( $source->get_name(), 0, strlen( $flag ) ) ) {
continue;
}
$mod = new \SearchWP\Mod( $source );
$mod->set_where( [ [
'column' => 'post_status',
'value' => [ 'publish' ],
'compare' => 'IN',
] ] );
$mods[] = $mod;
}
return $mods;
}, 20, 2 );

このコードの使用方法