\SearchWP\Statistics
\SearchWP\Statistics は、サイトで行われた訪問者の検索に関する統計データを生成するために使用できます。
基本的な使い方
\SearchWP\Statistics を使用して、次のように渡されたパラメータに基づいて記録されたデータを取得および表示できます。
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 | |
| // @link https://searchwp.com/documentation/classes/searchwp-statistics/ | |
| // Retrieve the most commmon searches for the | |
| // Default engine from the past thirty days. | |
| $statistics = \SearchWP\Statistics::get_popular_searches( [ | |
| 'days' => 30, | |
| 'engine' => 'default', | |
| ] ); | |
| // Display the results in a <table>. | |
| \SearchWP\Statistics::display( $statistics ); |
結果をさらに絞り込むために使用できる追加のパラメータがあります。
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 | |
| // @link https://searchwp.com/documentation/classes/searchwp-statistics/ | |
| $statistics = \SearchWP\Statistics::get_popular_searches( [ | |
| // 7 days old or newer. | |
| 'days' => 7, | |
| // The Engine used for searches. | |
| 'engine' => 'default', | |
| // The search queries to ignore i.e. spam, junk. | |
| 'exclude' => [ 'spam search query', 'lorem ipsum' ], | |
| // How many search queries to return. | |
| 'limit' => 5, | |
| // With at least one result. | |
| 'min_hits' => 1, | |
| // With at most 100 results. | |
| 'max_hits' => 100, | |
| // Which site(s) to consider. | |
| 'site' => [ get_current_blog_id() ], | |
| ] ); | |
| // Display the stats in a <table>. | |
| \SearchWP\Statistics::display( $statistics ); |
引数
\SearchWP\Statistics をインスタンス化する際に、受け入れられる引数はありません。
メソッド
get_popular_searches( array $args = [] )- 指定された引数に基づいて人気の検索を取得します。
- 次のパラメータを受け入れます
'days'(integer) 遡る日数。(デフォルト:1)'engine'(string) 考慮する\SearchWP\Engineの名前。(デフォルト:'default')'exclude'(string[]) 無視する検索語(例:スパム、ジャンク)。(デフォルト:[])'limit'(integer) 返される人気の検索の数。(デフォルト:10)'min_hits'(false|integer) 返される検索結果の最小数。(デフォルト:1)'max_hits'(false|integer) 返される検索結果の最大数。(デフォルト:false)'site'(integer[]) 返される検索のサイトID。(デフォルト:[ get_current_blog_id() ])
フック
\SearchWP\Statistics の動作をさらに変更するために使用できるフックがいくつかあります。

