Note: You are viewing the documentation for Version 4View Version 3 Docs

\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
// 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 );
view raw functions.php hosted with ❤ by GitHub

There are additional parameters you can use to further refine the results:

<?php
$statistics = \SearchWP\Statistics::get_popular_searches( [
// The number of days to go back.
'days' => 7,
// The Engine used for searches.
'engine' => 'default',
// The search queries to ignore i.e. spam, junk.
'exclude' => [ 'spam search query' ],
// How many search queries to return.
'limit' => 5,
// Minimum number of search results found.
'min_hits' => 1,
// Maximum number of search results found.
'max_hits' => 100,
// Which site(s) to consider.
'site'. => [ get_current_blog_id() ],
] );
// Display the stats in a <table>.
\SearchWP\Statistics::display( $statistics );
view raw functions.php hosted with ❤ by GitHub

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:

Fix keyword search on your site. No coding required!

Now you can utilize all of the content that's gone unrecognized by native WordPress keyword search instantly with SearchWP

Get SearchWP