Back to Functions and API

Updated on Jun 09, 2024

Database API Methods

The WP Slimstat plugin offers several methods to retrieve information from the database. You can use these methods in your plugin or theme to manipulate data before displaying it to visitors. Below is a straightforward guide to the available methods and their parameters.

init($_filters = '')

Purpose: Initializes the environment and converts user-friendly filters into a code-friendly array.

Parameters:

  • $_filters (string): The filters you want to apply to all subsequent API calls. Example format: “browser contains Fire&&&platform contains win”.

Notes: This method can be called multiple times to reset or change the filters.

count_records($_column = 'id', $_where = '', $_use_date_filters = true)

Purpose: Returns the number of pageviews matching the filters set during init.

Parameters:

  • $_column (string): The column to count (e.g., id, ip, resource, referrer). Almost any column in the wp_slim_stats table can be used.
  • $_where (string): A custom SQL WHERE clause to add to the filters.
  • $_use_date_filters (boolean): Whether to include date range filters in the SQL query. Defaults to true, limiting results to the current month.

Notes: Set $_use_date_filters to false if you want to count pageviews from the beginning without date restrictions.

get_recent($_column = 'id', $_where = '', $_having = '', $_use_date_filters = true, $_as_column = '', $_more_columns = '')

Purpose: Returns an array of popular records matching the filters set during init, ordered by pageview count.

Parameters:

  • $_column (string): The column to retrieve (e.g., IPs, resources, referrers). Almost any column in the wp_slim_stats table can be used.
  • $_where (string): A custom SQL WHERE clause to add to the filters.
  • $_having (string): An optional HAVING clause to filter results based on aggregate values (e.g., min, max, average).
  • $_use_date_filters (boolean): Whether to include date range filters in the SQL query. Defaults to true, limiting results to the current month.
  • $_as_column (string): An optional label to be appended to the column name, useful if your code requires different representations of the results.
  • $_more_columns (string): Optional additional dimensions to return.

These methods allow you to effectively query and manipulate your WP Slimstat data for customized reporting and analysis.