Back to Functions and API

Updated on Nov 05, 2023

Retrieving and outputting data from the database in PHP

There might be cases where you want to further process the information collected by Slimstat before it is displayed on your website. In cases like this, the functionality provided by a shortcode might not be flexible enough to accommodate your needs. Don’t worry, we’ve got you covered: our intuitive API functions will come to the rescue.

Let’s say you would like to know how many pageviews have been recorded in the last 5 minutes. With a shortcode, you would use the following code:

[slimstat f='count' w='id']strtotime equals now&&&interval_direction equals 1&&&interval_minutes equals 5[/slimstat]

For example, you could have a start date of February 1, 2017 and look at the next 5 days:

day equals 1&&&month equals 2&&&year equals 2017&&&interval equals 5

The API has a quite similar approach:

include_once( WP_PLUGIN_DIR . '/wp-slimstat/admin/view/wp-slimstat-db.php' );

wp_slimstat_db::init( 'strtotime equals now&&&interval_minutes equals 5' );
echo wp_slimstat_db::count_records( 'ip', '', true );

Basically, you need to:

  1. Include the file defining the API (we don’t make it available throughout WordPress to improve performance)
  2. Set the filters just like you would do for a shortcode
  3. Call the appropriate API function