SlimStat 6 launchfrom $34.30/yr1 site · 5 sites $83.30 · unlimited sites $139.3030% off every planEnds Nov 16 (UTC)

Functions and API

Database API Methods

Applies to SlimStat 6.0.0 and SlimStat Pro 3.0.0 · checked

Use wp_slimstat_db from a WordPress plugin or theme after WordPress and SlimStat have loaded. Front-end code may also need to load admin/view/wp-slimstat-db.php; the complete PHP example below shows that guard. Restrict private report output to authorized users, and escape values when displaying them.

Initialize filters

wp_slimstat_db::init( 'browser contains Firefox&&&limit_results equals 5', false );

init($_filters = '', bool $_use_request = true) sets filters and the default date window. Pass false for the second argument when your trusted query must ignore URL/form filters, as in this example. It changes shared report state, so isolate custom reporting code from unrelated report rendering.

Count records

$count = wp_slimstat_db::count_records( 'id', '', true );

count_records($_column = 'id', $_where = '', $_use_date_filters = true, $where_params = []) counts matching values. Use id for pageviews so rows without a stored IP still count. Turning date filters off includes all dates in the live pageview table; it does not automatically include archive tables or deleted records. SQL fragments must come from trusted code; use the parameter facility for values.

Recent records and top results are different

get_recent($_column = 'id', $_where = '', $_having = '', $_use_date_filters = true, $_as_column = '', $_more_columns = '', $_order_by = 'dt DESC') returns recent matching records. It does not rank by popularity.

get_top($_column = 'id', $_where = '', $_having = '', $_use_date_filters = true, $_as_column = '') returns grouped top results. Do not expose arbitrary SQL, sort expressions or column names from a URL parameter.

See a complete PHP example and the database schema. Use the plugin’s configured database connection when writing your own queries, so external-database installs keep working.