\SearchWP\Statistics
Table of Contents
\SearchWP\Statistics
facilitates generation of statistical data collected about visitor searches performed on your site.
Basic Usage
\SearchWP\Statistics
can be used to retrieve and display logged data based on passed parameters like so:
<?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 ); |
There are additional parameters you can use to further refine the results:
<?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 ); |
Arguments
There are no accepted arguments when instantiating \SearchWP\Statistics
.
Methods
get_popular_searches( array $args = [] )
- Retrieves popular searches based on the supplied arguments.
- Accepts the following parameters
'days'
(integer) The number of days to go back. (default:1
)'engine'
(string) The name of the\SearchWP\Engine
to consider. (default:'default'
)'exclude'
(string[]) Search terms to ignore e.g. spam, junk. (default:[]
)'limit'
(integer) The number of popular searches to return. (default:10
)'min_hits'
(false|integer) Minimum number of results returned for searches to be returned. (default:1
)'max_hits'
(false|integer) Maximum number of results returned for searches to be returned. (default:false
)'site'
(integer[]) Site ID(s) for searches to be returned. (default:[ get_current_blog_id() ]
)
Hooks
There are a number of hooks available to further modify the behavior of \SearchWP\Statistics
: