Skip to content

Instantly share code, notes, and snippets.

@tollmanz
Created October 12, 2012 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tollmanz/3882208 to your computer and use it in GitHub Desktop.
Save tollmanz/3882208 to your computer and use it in GitHub Desktop.
Get Google Analytics Data With Variable Arguments
<?php
function zt_get_top_posts( $args, $force = false ) {
// Define our cache key
$cache_key = 'zt-top-posts';
// Attempt to grab data from cache
$top_posts = wp_cache_get( $cache_key );
// If not found in cache or forced, regenerate
if ( false === $top_posts || true === $force ) {
// Get posts from GA
$top_posts = zt_generate_top_posts( $args );
// If none were found, save a dummy value so the caller knows that
if ( false === $top_posts )
$top_posts = 'none-found';
// Set the result to the cache
wp_cache_set( $cache_key, $top_posts, 3600 );
}
return $top_posts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment