Created
October 12, 2012 23:20
-
-
Save tollmanz/3882208 to your computer and use it in GitHub Desktop.
Get Google Analytics Data With Variable Arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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