Created
May 14, 2014 14:43
-
-
Save jorgeguberte/f53758b98d4053771848 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/* | |
* Template Name: Tokenizador | |
*/ | |
$token_input = $_GET['key'];// Variável que acomoda a key vinda da url. | |
$base_url = get_bloginfo('url').'/'; //URL base do site atual. | |
$outbound_url = ''; //Variável que acomoda a url de destino. | |
if(!$token_input) | |
header('Location: '.$base_url); | |
//Get stuff from db | |
global $wpdb; | |
$results = $wpdb->get_results("SELECT * FROM wp_postmeta WHERE meta_key = 'key'"); | |
$posts_with_key = array(); | |
$key_matches = false; | |
$outbound_url = get_bloginfo('url'); | |
foreach($results as $result){ | |
$_stuff = array('post_id'=>$result->post_id, 'meta_value'=>$result->meta_value); | |
array_push($posts_with_key, $_stuff); | |
} | |
function getThePost($id){ | |
$the_post = get_post($id); | |
return $the_post; | |
} | |
function findInArray($meta_value, $posts_with_key){ | |
foreach($posts_with_key as $post){ | |
if($meta_value == $post['meta_value']) | |
return $post; | |
} | |
return false; | |
} | |
$found_post = findInArray($token_input, $posts_with_key); | |
if($found_post !== false){ | |
$post = getThePost($found_post['post_id']); | |
$redirection_url = $post->guid.'&key='.$token_input; | |
}else{ | |
$redirection_url = get_bloginfo('url'); | |
} | |
header('Location: '.$redirection_url); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment