Skip to content

Instantly share code, notes, and snippets.

@clarklab
Created July 6, 2012 03:12
Show Gist options
  • Select an option

  • Save clarklab/3057857 to your computer and use it in GitHub Desktop.

Select an option

Save clarklab/3057857 to your computer and use it in GitHub Desktop.
Simple redirect (URL shortener / tracker) page template
<?php
/*
Template Name: Redirect
*/
$redirect_url = get_post_meta($post->ID, 'redirect_url', true);
// get the destination URL
$count = get_post_meta($post->ID, 'count', true);
// get the number of times it's been clicked
$count = $count +1;
//add 1 to the count
update_post_meta($post->ID, 'count', $count);
// update the count post meta
if ($redirect_url) {
wp_redirect($redirect_url);
// shoot the user to the destination URL
} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment