\SearchWP\Statistics
Indice
\SearchWP\Statistics facilita la generazione di dati statistici raccolti sulle ricerche dei visitatori effettuate sul tuo sito.
Utilizzo di base
\SearchWP\Statistics può essere utilizzato per recuperare e visualizzare dati registrati in base ai parametri passati in questo modo:
| <?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 ); |
Ci sono parametri aggiuntivi che puoi utilizzare per affinare ulteriormente i risultati:
| <?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 ); |
Argomenti
Non ci sono argomenti accettati durante l'istanziazione di \SearchWP\Statistics.
Metodi
get_popular_searches( array $args = [] )- Recupera le ricerche più popolari in base agli argomenti forniti.
- Accetta i seguenti parametri
'days'(integer) Il numero di giorni da considerare. (default:1)'engine'(string) Il nome di\SearchWP\Engineda considerare. (default:'default')'exclude'(string[]) Termini di ricerca da ignorare, ad es. spam, junk. (default:[])'limit'(integer) Il numero di ricerche popolari da restituire. (default:10)'min_hits'(false|integer) Numero minimo di risultati restituiti per le ricerche da visualizzare. (default:1)'max_hits'(false|integer) Numero massimo di risultati restituiti per le ricerche da visualizzare. (default:false)'site'(integer[]) ID del sito o dei siti per le ricerche da visualizzare. (default:[ get_current_blog_id() ])
Hook
Sono disponibili diversi hook per modificare ulteriormente il comportamento di \SearchWP\Statistics:

